﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DAL;
namespace BLL
{
    public class CmsBLL
    {        

        DataService DB = new DataService();
        private static DataTable dtCart;
        string PaymentMethodID = "B879E958-C72E-4101-AB92-A320225125CE"; // Tiền mặt
        #region TableCategory - GetData
        //public DataTable Category_GetTree(int CateID)
        //{
        //    string Query = "IF @CateID =0  " +
        //                "BEGIN " +
        //                "	Select tc.CateID, tc.ParentID,  " +
        //                "	Case tc.Decen  " +
        //                "		When 0 Then tc.Title " +
        //                "		When 1 Then ':: '+ tc.Title " +
        //                "		When 2 Then ':: :: ' + tc.Title " +
        //                "		When 3 Then ':: :: :: ' + tc.Title " +
        //                "		When 4 Then ':: :: :: :: ' + tc.Title " +
        //                "	End " +
        //                "	As _Title, " +
        //                "	tc.Title, tc.Url, tc.Decen, tc.Depth, tc.Active, " +
        //                "		   Case Active When 1 Then N'Có' " +
        //                "		When 0 Then N'Không' END As _Active " +
        //                "	  From tbl_Category tc  " +
        //                "	 " +
        //                "	Order By tc.Depth  " +
        //                "End " +
        //                "ELSE " +
        //                "BEGIN " +
        //                "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Url, tc.Active " +
        //                "	From tbl_Category tc  " +
        //                "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Category WHERE CateID=@CateID) + '%' " +
        //                "	ORDER By tc.Depth asc  " +
        //                "END ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@CateID", SqlDbType.Int)};
        //    arrParam[0].Value = CateID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public DataTable Category_GetTreeActive(int CateID)
        //{
        //    string Query = "IF @CateID =0  " +
        //                "BEGIN " +
        //                "	Select tc.CateID, tc.ParentID,  " +
        //                "	Case tc.Decen  " +
        //                "		When 0 Then tc.Title " +
        //                "		When 1 Then ':: '+ tc.Title " +
        //                "		When 2 Then ':: :: ' + tc.Title " +
        //                "		When 3 Then ':: :: :: ' + tc.Title " +
        //                "		When 4 Then ':: :: :: :: ' + tc.Title " +
        //                "	End " +
        //                "	As _Title, " +
        //                "	tc.Title, tc.Url, tc.Decen, tc.Depth, tc.Active, " +
        //                "		   Case Active When 1 Then N'Có' " +
        //                "		When 0 Then N'Không' END As _Active " +
        //                "	  From tbl_Category tc  " +
        //                "	Where tc.Active=1 " +
        //                "	Order By tc.Depth  " +
        //                "End " +
        //                "ELSE " +
        //                "BEGIN " +
        //                "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Url, tc.Active " +
        //                "	From tbl_Category tc  " +
        //                "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Category WHERE CateID=@CateID) + '%' and tc.Active=1 " +
        //                "	ORDER By tc.Depth asc  " +
        //                "END ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@CateID", SqlDbType.Int)};
        //    arrParam[0].Value = CateID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void Category_UpDateItem(int CateID, int ParentID, string Title, string Url, int Active)
        //{
        //    string Query = "Update tbl_Category " +
        //                "Set " +
        //                "	ParentID=@ParentID, " +
        //                "	Title=@Title, " +                     
        //                "	Url=@Url, " +                     
        //                "	Active=@Active " +
        //                "Where CateID=@CateID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@CateID", SqlDbType.Int),
        //            new SqlParameter("@ParentID", SqlDbType.Int),
        //            new SqlParameter("@Title", SqlDbType.NVarChar),               
        //            new SqlParameter("@Url", SqlDbType.NVarChar),                 
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = CateID;
        //    arrParam[1].Value = ParentID;
        //    arrParam[2].Value = Title;         
        //    arrParam[3].Value = Url;         
        //    arrParam[4].Value = Active;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public void DeleteItemFromtblCategory(int ItemID)
        //{
        //    string Query = "Delete From tbl_Category" +
        //                " Where CateID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public string tblCategoryGetTitle(int ItemID)
        //{
        //    string Value = string.Empty;
        //    string Query = "Select Title From tbl_Category" +
        //                " Where CateID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    Value = DB.ExeCuteScalarParam(Query, arrParam);
        //    return Value;
        //}
        //public DataTable Category_Search(int CateID, string Keyword)
        //{
        //    string Query = "Declare @SQL nvarchar(4000), @SQLDK1 nvarchar(1000), @SQLDK2 nvarchar(1000), @SQLOrder varchar(200) " +
        //                "Set @SQLDK1='' " +
        //                "Set @SQLDK2='' " +
        //                "Set @SQL=N'Select CateID, ParentID,  " +
        //                "	Case Decen  " +
        //                "		When 0 Then Title " +
        //                "		When 1 Then '':: ''+ Title " +
        //                "		When 2 Then '':: :: '' + Title " +
        //                "		When 3 Then '':: :: ::'' + Title " +
        //                "		When 4 Then '':: :: :: :: '' + Title " +
        //                "	End " +
        //                "	As _Title, " +
        //                "	Title, Decen, Depth, Url, Active, " +
        //                "    Case Active " +
        //                "		   When 1 Then N''Có'' " +
        //                "		   When 0 Then N''Không''  " +
        //                "	END As _Active " +
        //                "	From tbl_Category where ''1''=''1''' " +
        //                "	If @CateID>0 " +
        //                "		Set @SQLDK1=' And Depth LIKE(Select Depth From tbl_Category " +
        //                "		Where tbl_Category.CateID='+cast(@CateID as varchar(10)) +')+''%''' " +
        //                "    If @Keyword<>'' " +
        //                "		Set @SQLDK2=' And(Title like N''%'+@Keyword+'%'' Or Url like N''%'+@Keyword+'%'')' " +
        //                "    Set @SQLOrder='Order by Depth' " +
        //                "    Exec (@SQL+@SQLDK1+@SQLDK2+@SQLOrder) ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@CateID", SqlDbType.Int),                   
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = CateID;
        //    arrParam[1].Value = Keyword;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void Category_InsertItem(int ParentID, string Title, string Url, int Active)
        //{
        //    string Query = "Insert Into tbl_Category( " +
        //                "ParentID,Title,Url,Active) " +
        //                "Values(@ParentID,@Title,@Url,@Active) ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ParentID", SqlDbType.Int),
        //            new SqlParameter("@Title", SqlDbType.NVarChar),                   
        //            new SqlParameter("@Url", SqlDbType.NVarChar),                 
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = ParentID;
        //    arrParam[1].Value = Title;
        //    arrParam[2].Value = Url;
        //    arrParam[3].Value = Active;          
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public DataTable ViewItemCategoryByCateID(int ItemID)
        //{
        //    string Query = "Select CateID, ParentID, Title, Url, Active, " +
        //                "	Case Active When 1 Then N'Có' " +
        //                "	When 0 Then N'Không' END As _Active From tbl_Category " +
        //                "	Where CateID=@ItemID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public string CategoryGetParentNameByCateID(int ParentID)
        //{
        //    string Query = "Select Title From tbl_Category " +
        //                "	Where CateID=@ParentID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ParentID", SqlDbType.Int)};
        //    arrParam[0].Value = ParentID;
        //    return DB.ExeCuteScalarParam(Query, arrParam);
        //}
        public DataTable Category_GetTree(int CateID, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("tc", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "	ORDER By tc.Depth asc  ";
            string Query = "IF @CateID =0  " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Image, tc.Url, tc.Decen, tc.Depth, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_Category tc  " +
                        "	 " +
                        OrderBy +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Image, tc.Url, tc.Active " +
                        "	From tbl_Category tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Category WHERE CateID=@CateID) + '%' " +
                        OrderBy +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Category_GetTree(int CateID)
        {
            string Query = "IF @CateID =0  " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then '-- '+ tc.Title " +
                        "		When 2 Then '-- --' + tc.Title " +
                        "		When 3 Then '-- -- -- ' + tc.Title " +
                        "		When 4 Then '-- -- -- -- ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Image, tc.Url, tc.Decen, tc.Depth, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_Category tc  " +
                        "	 " +
                        "	ORDER By tc.Depth " +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Image, tc.Url, tc.Active " +
                        "	From tbl_Category tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Category WHERE CateID=@CateID) + '%' " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Category_GetSubItems(int CateID)
        {
            string Query = " SELECT CateID,ParentID,Title,Decen,Depth,Image,Url,Active " +
                        " FROM tbl_Category " +
                        " WHERE ParentID = @CateID " +
                        "	ORDER By Depth asc  ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Category_GetTreeActive(int CateID)
        {
            string Query = "IF @CateID =0  " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Image, tc.Url, tc.Decen, tc.Depth, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_Category tc  " +
                        "	Where tc.Active=1 " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Image, tc.Url, tc.Active " +
                        "	From tbl_Category tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Category WHERE CateID=@CateID) + '%' and tc.Active=1 " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Category_UpDateItem(int CateID, int ParentID, string Title, string Image, string Url, int Active)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(Image))
            {
                Query = "Update tbl_Category " +
                        "Set " +
                        "	ParentID=@ParentID, " +
                        "	Title=@Title, " +
                        "   Image=@Image, " +
                        "	Url=@Url, " +
                        "	Active=@Active " +
                        "Where CateID=@CateID";
            }
            else
            {
                Query = "Update tbl_Category " +
                        "Set " +
                        "	ParentID=@ParentID, " +
                        "	Title=@Title, " +
                        "	Url=@Url, " +
                        "	Active=@Active " +
                        "Where CateID=@CateID";
            }
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),           
                    new SqlParameter("@Image", SqlDbType.NVarChar), 
                    new SqlParameter("@Url", SqlDbType.NVarChar),                 
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = ParentID;
            arrParam[2].Value = Title;
            arrParam[3].Value = Image;
            arrParam[4].Value = Url;
            arrParam[5].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string Category_DeleteItemString(string CatId)
        {
            string reV = string.Empty;
            try
            {
                string Query =

                    " Delete from tbl_Filter where GroupFilterID in " +
                    " (select GroupFilterID from tbl_GroupFilters where CateID = @CatId ) ;" +

                    " Delete From tbl_GroupFilters " +
                            " Where CateID=@CatId ;" +

                    " Update tbl_Order set StatusOrderID = 5 where  OrderID in " +
                    " ( select OrderID from tbl_OrderDetail where ProductID in ( "+
                    " select ProductId from tbl_Products where CateID = @CatId     ) ) ;" +

                    " Delete from tbl_OrderDetail where ProductID in " +
                    " (select ProductId from tbl_Products where CateID = @CatId ) ;" +

                    " Delete From tbl_Products " +
                            " Where CateID=@CatId ;" +

                    " Delete From tbl_Category" +
                            " Where CateID=@CatId ";

                SqlParameter[] arrParam ={
                    new SqlParameter("@CatId", SqlDbType.Int)};
                arrParam[0].Value = int.Parse(CatId);
                DB.ExeCuteSqlParam(Query, arrParam);
            }
            catch (Exception ex)
            {
                reV = "ERROR: " + ex.Message;
            }
            return reV;
        }

        public string Category_DeleteItem(int CatId)
        {
            string reV = string.Empty;
            try
            {
                string Query =


                  " Delete from tbl_Filter where GroupFilterID in " +
                    " (select GroupFilterID from tbl_GroupFilters where CateID = @CatId ) ;" +

                    " Delete From tbl_GroupFilters " +
                            " Where CateID=@CatId ;" +

                    " Delete from tbl_OrderDetail where ProductID in " +
                    " (select ProductId from tbl_Products where CateID = @CatId ) ;" +

                    " Delete From tbl_Products " +
                            " Where CateID=@CatId ;" +

                    " Delete From tbl_Category" +
                            " Where CateID=@CatId ";

                SqlParameter[] arrParam ={
                    new SqlParameter("@CatId", SqlDbType.Int)};
                arrParam[0].Value = CatId;
                DB.ExeCuteSqlParam(Query, arrParam);
            }
            catch (Exception ex)
            {
                reV = "ERROR: " + ex.Message;
            }
            return reV;
        }


        public string Category_GetTitle(int ItemID)
        {
            string Value = string.Empty;
            try
            {
                string Query = "Select Title From tbl_Category" +
                            " Where CateID=@ItemID";
                SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
                arrParam[0].Value = ItemID;
                Value = DB.ExeCuteScalarParam(Query, arrParam);
            }
            catch (Exception ex) {
                Value = "";
            }
            return Value;
        }
        public string Category_GetTotalSubCategory(int ItemID)
        {
            string Value = string.Empty;
            string Query = "Select Count(*) From tbl_Category Where ParentID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Category_GetParentIDByCateID(int CateID)
        {
            string Value = string.Empty;
            string Query = "Select ParentID From tbl_Category Where CateID=@CateID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Category_Search(int CateID, string Keyword)
        {
            string Query = " Select CateID, ParentID,  " +
                        "	Case Decen  " +
                        "		When 0 Then Title " +
                        "		When 1 Then ':: '+ Title " +
                        "		When 2 Then ':: :: ' + Title " +
                        "		When 3 Then ':: :: :: ' + Title " +
                        "		When 4 Then ':: :: :: :: ' + Title " +
                        "	End " +
                        "	As _Title, " +
                        "	Title, Decen, Depth, Image, Url, Active, " +
                        "    Case Active " +
                        "		   When 1 Then N'Có' " +
                        "		   When 0 Then N'Không'  " +
                        "	END As _Active " +
                        "	From tbl_Category where 1=1 ";
            if (CateID > 0)
                Query += " And Depth LIKE(Select Depth From tbl_Category " +
                        "		Where tbl_Category.CateID=@CateID)+'%' ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And(Title like N'%'+@Keyword+'%' Or Url like N'%'+@Keyword+'%') ";
            Query += " Order by Depth ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),                   
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Category_InsertItem(int ParentID, string Title, string Image, string Url, int Active)
        {
            string Query = "Insert Into tbl_Category( " +
                        " ParentID,Title,Image,Url,Active) " +
                        " Values(@ParentID,@Title,@Image, @Url,@Active) ";

            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),  
                    new SqlParameter("@Image", SqlDbType.NVarChar),  
                    new SqlParameter("@Url", SqlDbType.NVarChar),                 
                    new SqlParameter("@Active", SqlDbType.Int)};

            arrParam[0].Value = ParentID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Image;
            arrParam[3].Value = Url;
            arrParam[4].Value = Active;

            DB.ExeCuteSqlParam(Query, arrParam);
        }
       

        public DataTable Category_ViewItemByCateID(int ItemID)
        {
            string Query = "Select CateID, ParentID, Title, Image, Url, Active, " +
                        "	Case Active When 1 Then N'Có' " +
                        "	When 0 Then N'Không' END As _Active From tbl_Category " +
                        "	Where CateID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string Category_GetParentNameByCateID(int ParentID)
        {
            string Query = "Select Title From tbl_Category " +
                        "	Where CateID=@ParentID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableMenu - GetData
        //public DataTable ReadingMenuTop()
        //{
        //    string Query = "Select MenuID, ParentID, Title, Description, Url, Target  From tbl_Menu" +
        //                " Where Active = 1 and Location=1" +
        //                " Order By SortIndex desc";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public DataTable ReadingMenuBar()
        //{
        //    string Query = "Select MenuID, ParentID, Title, Description, Url, Target  From tbl_Menu" +
        //                " Where Active = 1 and Location=2 and ParentID =0" +
        //                " Order By SortIndex";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public DataTable ReadingMenuChild(int Parent)
        //{
        //    string Query = "Select MenuID, ParentID, Title, Description, Url, Target  From tbl_Menu" +
        //                " Where Active = 1 and Location=2 and ParentID=@Parent" +
        //                " Order By SortIndex";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@Parent", SqlDbType.Int)};
        //    arrParam[0].Value = Parent;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public DataTable GetListMenu(int MenuID)
        //{
        //    string Query = "IF @MenuID =0  " +
        //                "BEGIN " +
        //                "	Select tc.MenuID, tc.ParentID,  " +
        //                "	Case tc.Decen  " +
        //                "		When 0 Then tc.Title " +
        //                "		When 1 Then ':: '+ tc.Title " +
        //                "		When 2 Then ':: :: ' + tc.Title " +
        //                "		When 3 Then ':: :: :: ' + tc.Title " +
        //                "		When 4 Then ':: :: :: :: ' + tc.Title " +
        //                "	End " +
        //                "	As _Title, " +
        //                "	tc.Title, tc.Decen, tc.Depth, " +
        //                "		   tc.Url, tc.Location, "+
        //                "		   Case tc.Location When 1 Then 'MenuTop' " +
        //                "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.SortIndex, tc.Active, " +
        //                "		   Case Active When 1 Then N'Có' " +
        //                "		When 0 Then N'Không' END As _Active " +
        //                "	  From tbl_Menu tc  " +
        //                "	 " +
        //                "	Order By tc.Depth  " +
        //                "End " +
        //                "	-- Ngược lại Get Sub Tree " +
        //                "ELSE " +
        //                "BEGIN " +
        //                "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, " +
        //                "	   tc.Url, tc.Location, " +
        //                "		   Case Location When 1 Then 'MenuTop' " +
        //                "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.SortIndex, tc.Active " +
        //                "	From tbl_Menu tc  " +
        //                "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Menu WHERE MenuID=@MenuID) + '%' " +
        //                "	ORDER By tc.Depth asc  " +
        //                "END ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int)};
        //    arrParam[0].Value = MenuID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public DataTable Menu_GetTree(int MenuID)
        //{
        //    string Query = "IF @MenuID =0  " +
        //                "BEGIN " +
        //                "	Select tc.MenuID, tc.ParentID,  " +
        //                "	Case tc.Decen  " +
        //                "		When 0 Then tc.Title " +
        //                "		When 1 Then ':: '+ tc.Title " +
        //                "		When 2 Then ':: :: ' + tc.Title " +
        //                "		When 3 Then ':: :: :: ' + tc.Title " +
        //                "		When 4 Then ':: :: :: :: ' + tc.Title " +
        //                "	End " +
        //                "	As _Title, " +
        //                "	tc.Title, tc.Description, tc.Url, tc.Location, "+
        //                "   Case tc.Location When 1 Then 'MenuTop' " +
        //                "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.Decen, tc.Depth, " +
        //                "		tc.Target, tc.SortIndex, tc.Active, " +
        //                "		   Case Active When 1 Then N'Có' " +
        //                "		When 0 Then N'Không' END As _Active " +
        //                "	  From tbl_Menu tc  " +
        //                "	 " +
        //                "	Order By tc.Depth  " +
        //                "End " +
        //                "ELSE " +
        //                "BEGIN " +
        //                "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Description, " +
        //                "	   tc.Url, tc.Location, " +
        //                "   Case Location When 1 Then 'MenuTop' " +
        //                "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.Target, tc.SortIndex, tc.Active " +
        //                "	From tbl_Menu tc  " +
        //                "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Menu WHERE MenuID=@MenuID) + '%' " +
        //                "	ORDER By tc.Depth asc  " +
        //                "END ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int)};
        //    arrParam[0].Value = MenuID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public int CountSubItemMenuByParentID(int MenuID)
        //{
        //    string Query = "Select Count(*) as SL From tbl_Menu" +
        //                " Where ParentID=@MenuID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int)};
        //    arrParam[0].Value = MenuID;
        //    return int.Parse(DB.ExeCuteScalarParam(Query, arrParam));
        //}
        //public void DeleteItemFromtblMenu(int MenuID)
        //{
        //    string Query = "Delete From tbl_Menu" +
        //                " Where MenuID=@MenuID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int)};
        //    arrParam[0].Value = MenuID;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public string tblMenuGetTitle(int MenuID)
        //{
        //    string Value = string.Empty;
        //    string Query = "Select Title From tbl_Menu" +
        //                " Where MenuID=@MenuID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int)};
        //    arrParam[0].Value = MenuID;
        //    Value = DB.ExeCuteScalarParam(Query, arrParam);
        //    return Value;
        //}
        //public DataTable Menu_Search(int MenuID, int Location, string Keyword)
        //{
        //    string Query = "Declare @SQL nvarchar(4000), @SQLDK1 nvarchar(1000), @SQLDK2 nvarchar(1000),@SQLDK3 nvarchar(1000), @SQLOrder varchar(200) " +
        //                "Set @SQLDK1='' " +
        //                "Set @SQLDK2='' " +
        //                "Set @SQLDK3='' " +
        //                "Set @SQL=N'Select MenuID, ParentID,  " +
        //                "	Case Decen  " +
        //                "		When 0 Then Title " +
        //                "		When 1 Then '':: ''+ Title " +
        //                "		When 2 Then '':: :: '' + Title " +
        //                "		When 3 Then '':: :: ::'' + Title " +
        //                "		When 4 Then '':: :: :: :: '' + Title " +
        //                "	End " +
        //                "	As _Title, " +
        //                "	Title, Decen, Depth, Description, Url, Location, " +
        //                "   Case Location When 1 Then ''MenuTop'' " +
        //                "		When 2 Then ''MenuBar'' When 3 Then ''MenuSPKM'' When 4 Then ''MenuSPMoi'' END As _Location, Target, SortIndex, Active, " +
        //                "    Case Active " +
        //                "		   When 1 Then N''Có'' " +
        //                "		   When 0 Then N''Không''  " +
        //                "	END As _Active " +
        //                "	From tbl_Menu where ''1''=''1''' " +
        //                "	If @MenuID>0 " +
        //                "		Set @SQLDK1=' And Depth LIKE(Select Depth From tbl_Menu " +
        //                "		Where tbl_Menu.MenuID='+cast(@MenuID as varchar(10)) +')+''%''' " +
        //                "	If @Location>0 " +
        //                "		Set @SQLDK2=' And Location='+cast(@Location as varchar(10)) +'' " +
        //                "    If @Keyword<>'' " +
        //                "		Set @SQLDK3=' And(Title like N''%'+@Keyword+'%'' Or Description like N''%'+@Keyword+'%'' Or Url like N''%'+@Keyword+'%'')' " +
        //                "    Set @SQLOrder='Order by Depth' " +
        //                "    Exec (@SQL+@SQLDK1+@SQLDK2+@SQLDK3+@SQLOrder) ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int),
        //            new SqlParameter("@Location", SqlDbType.Int),
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = MenuID;
        //    arrParam[1].Value = Location;
        //    arrParam[2].Value = Keyword;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void Menu_InsertItem(int ParentID, string Title, string Description, string Url, int Location, int Target, int SortIndex, int Active)
        //{
        //    string Query = "Insert Into tbl_Menu( " +
        //                "ParentID,Title,Description,Url,Location,Target,SortIndex,Active) " +
        //                "Values(@ParentID,@Title,@Description,@Url,@Location,@Target,@SortIndex,@Active) ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ParentID", SqlDbType.Int),
        //            new SqlParameter("@Title", SqlDbType.NVarChar),
        //            new SqlParameter("@Description", SqlDbType.NVarChar),
        //            new SqlParameter("@Url", SqlDbType.NVarChar),
        //            new SqlParameter("@Location", SqlDbType.Int),
        //            new SqlParameter("@Target", SqlDbType.Int),
        //            new SqlParameter("@SortIndex", SqlDbType.Int),
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = ParentID;
        //    arrParam[1].Value = Title;
        //    arrParam[2].Value = Description;
        //    arrParam[3].Value = Url;
        //    arrParam[4].Value = Location;
        //    arrParam[5].Value = Target;
        //    arrParam[6].Value = SortIndex;
        //    arrParam[7].Value = Active;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public void Menu_UpDateItem(int MenuID, int ParentID, string Title, string Description, string Url, int Location, int Target, int SortIndex, int Active)
        //{
        //    string Query = "Update tbl_Menu " +
        //                "Set " +
        //                "	ParentID=@ParentID, " +
        //                "	Title=@Title, " +
        //                "	Description=@Description, " +
        //                "	Url=@Url, " +
        //                "	Location=@Location, " +
        //                "	Target=@Target,	 " +
        //                "	SortIndex=@SortIndex, " +
        //                "	Active=@Active " +
        //                "Where MenuID=@MenuID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@MenuID", SqlDbType.Int),
        //            new SqlParameter("@ParentID", SqlDbType.Int),
        //            new SqlParameter("@Title", SqlDbType.NVarChar),
        //            new SqlParameter("@Description", SqlDbType.NVarChar),
        //            new SqlParameter("@Url", SqlDbType.NVarChar),
        //            new SqlParameter("@Location", SqlDbType.Int),
        //            new SqlParameter("@Target", SqlDbType.Int),               
        //            new SqlParameter("@SortIndex", SqlDbType.Int),
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = MenuID;
        //    arrParam[1].Value = ParentID;
        //    arrParam[2].Value = Title;
        //    arrParam[3].Value = Description;
        //    arrParam[4].Value = Url;
        //    arrParam[5].Value = Location;
        //    arrParam[6].Value = Target;
        //    arrParam[7].Value = SortIndex;
        //    arrParam[8].Value = Active;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public DataTable ViewItemMenuByMenuID(int ItemID)
        //{
        //    string Query = "Select MenuID, ParentID, Title, Description, Url, Location, " +
        //                "   Case Location When 1 Then 'MenuTop' " +
        //                "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location,  " +
        //                "	Case Target When 1 Then '_blank' " +
        //                "		When 0 Then '_self' END As _Target, SortIndex, " +
        //                "	Case Active When 1 Then N'Có' " +
        //                "	When 0 Then N'Không' END As _Active From tbl_Menu " +
        //                "	Where MenuID=@ItemID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public string MenuGetParentNameByMenuID(int ParentID)
        //{
        //    string Query = "Select Title From tbl_Menu " +
        //                "	Where MenuID=@ParentID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ParentID", SqlDbType.Int)};
        //    arrParam[0].Value = ParentID;
        //    return DB.ExeCuteScalarParam(Query, arrParam);
        //}
        public DataTable Menu_GetMenuNewProducts()
        {
            string Query = "Select Title, Description, Url, Target  From tbl_Menu" +
                        "	Where Active = 1 and Location=4" +
                        "	Order By SortIndex";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Menu_GetMenuKhuyenMai()
        {
            string Query = "Select Title, Description, Url, Target  From tbl_Menu" +
                        "	Where Active = 1 and Location=3" +
                        "	Order By SortIndex";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Menu_GetMenuTop()
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url, Target  From tbl_Menu" +
                        " Where Active = 1 and Location=1" +
                        " Order By SortIndex desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Menu_GetMenuBar()
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url, Target  From tbl_Menu" +
                        " Where Active = 1 and Location=2 and ParentID =0" +
                        " Order By SortIndex";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Menu_GetMenuChild(int Parent)
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url, Target  From tbl_Menu" +
                        " Where Active = 1 and Location=2 and ParentID=@Parent" +
                        " Order By SortIndex";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Parent", SqlDbType.Int)};
            arrParam[0].Value = Parent;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Menu_GetListMenu(int MenuID)
        {
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Location, " +
                        "		   Case tc.Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_Menu tc  " +
                        "	 " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "	-- Ngược lại Get Sub Tree " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, " +
                        "	   tc.Url, tc.Location, " +
                        "		   Case Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.SortIndex, tc.Active " +
                        "	From tbl_Menu tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Menu WHERE MenuID=@MenuID) + '%' " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Menu_GetListMenu(int MenuID, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("tc", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "	ORDER By tc.Depth asc  ";
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Location, " +
                        "		   Case tc.Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_Menu tc  " +
                        "	 " +
                        OrderBy +
                        "End " +
                        "	-- Ngược lại Get Sub Tree " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, " +
                        "	   tc.Url, tc.Location, " +
                        "		   Case Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.SortIndex, tc.Active " +
                        "	From tbl_Menu tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Menu WHERE MenuID=@MenuID) + '%' " +
                        OrderBy +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Menu_GetTree(int MenuID)
        {
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Description, tc.Url, tc.Location, " +
                        "   Case tc.Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.Decen, tc.Depth, " +
                        "		tc.Target, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_Menu tc  " +
                        "	 " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Description, " +
                        "	   tc.Url, tc.Location, " +
                        "   Case Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, tc.Target, tc.SortIndex, tc.Active " +
                        "	From tbl_Menu tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_Menu WHERE MenuID=@MenuID) + '%' " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public int Menu_CountSubItemByParentID(int MenuID)
        {
            string Query = "Select Count(*) as SL From tbl_Menu" +
                        " Where ParentID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            return int.Parse(DB.ExeCuteScalarParam(Query, arrParam));
        }
        public void Menu_DeleteItem(int MenuID)
        {
            string Query = "Delete From tbl_Menu" +
                        " Where MenuID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Menu_GetTitle(int MenuID)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_Menu" +
                        " Where MenuID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Menu_Search(int MenuID, int Location, string Keyword)
        {
            string Query = " Select MenuID, ParentID,  " +
                        "	Case Decen  " +
                        "		When 0 Then Title " +
                        "		When 1 Then ':: '+ Title " +
                        "		When 2 Then ':: :: ' + Title " +
                        "		When 3 Then ':: :: :: ' + Title " +
                        "		When 4 Then ':: :: :: :: ' + Title " +
                        "	End " +
                        "	As _Title, " +
                        "	Title, Decen, Depth, Description, Url, Location, " +
                        "   Case Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location, Target, SortIndex, Active, " +
                        "    Case Active " +
                        "		   When 1 Then N'Có' " +
                        "		   When 0 Then N'Không'  " +
                        "	END As _Active " +
                        "	From tbl_Menu where 1=1 ";
            if (MenuID > 0)
                Query += " And Depth LIKE(Select Depth From tbl_Menu " +
                        "		Where tbl_Menu.MenuID=@MenuID)+'%' ";
            if (Location > 0)
                Query += " And Location=@Location ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And(Title like N'%'+@Keyword+'%' Or Description like N'%'+@Keyword+'%' Or Url like N'%'+@Keyword+'%') ";
            Query += " Order by Depth ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int),
                    new SqlParameter("@Location", SqlDbType.Int),
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = MenuID;
            arrParam[1].Value = Location;
            arrParam[2].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Menu_InsertItem(int ParentID, string Title, string Description, string Url, int Location, int Target, int SortIndex, int Active)
        {
            string Query = "Insert Into tbl_Menu( " +
                        "ParentID,Title,Description,Url,Location,Target,SortIndex,Active) " +
                        "Values(@ParentID,@Title,@Description,@Url,@Location,@Target,@SortIndex,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),
                    new SqlParameter("@Location", SqlDbType.Int),
                    new SqlParameter("@Target", SqlDbType.Int),
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Description;
            arrParam[3].Value = Url;
            arrParam[4].Value = Location;
            arrParam[5].Value = Target;
            arrParam[6].Value = SortIndex;
            arrParam[7].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Menu_UpDateItem(int MenuID, int ParentID, string Title, string Description, string Url, int Location, int Target, int SortIndex, int Active)
        {
            string Query = "Update tbl_Menu " +
                        "Set " +
                        "	ParentID=@ParentID, " +
                        "	Title=@Title, " +
                        "	Description=@Description, " +
                        "	Url=@Url, " +
                        "	Location=@Location, " +
                        "	Target=@Target,	 " +
                        "	SortIndex=@SortIndex, " +
                        "	Active=@Active " +
                        "Where MenuID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int),
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),
                    new SqlParameter("@Location", SqlDbType.Int),
                    new SqlParameter("@Target", SqlDbType.Int),               
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            arrParam[1].Value = ParentID;
            arrParam[2].Value = Title;
            arrParam[3].Value = Description;
            arrParam[4].Value = Url;
            arrParam[5].Value = Location;
            arrParam[6].Value = Target;
            arrParam[7].Value = SortIndex;
            arrParam[8].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable Menu_ViewItemByMenuID(int ItemID)
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url, Location, " +
                        "   Case Location When 1 Then 'MenuTop' " +
                        "		When 2 Then 'MenuBar' When 3 Then 'MenuSPKM' When 4 Then 'MenuSPMoi' END As _Location,  " +
                        "	Case Target When 1 Then '_blank' " +
                        "		When 0 Then '_self' END As _Target, SortIndex, " +
                        "	Case Active When 1 Then N'Có' " +
                        "	When 0 Then N'Không' END As _Active From tbl_Menu " +
                        "	Where MenuID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string Menu_GetParentNameByMenuID(int ParentID)
        {
            string Query = "Select Title From tbl_Menu " +
                        "	Where MenuID=@ParentID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableLeftMenu - GetData
        public DataTable LeftMenu_GetList(int MenuID)
        {
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_LeftMenu tc  " +
                        "	 " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "	-- Ngược lại Get Sub Tree " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, " +
                        "	   tc.Url, tc.Active " +
                        "	From tbl_LeftMenu tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_LeftMenu WHERE MenuID=@MenuID) + '%' " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable LeftMenu_GetList(int MenuID, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("tc", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "	ORDER By tc.Depth asc  ";
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_LeftMenu tc  " +
                        "	 " +
                         OrderBy +
                        "End " +
                        "	-- Ngược lại Get Sub Tree " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, " +
                        "	   tc.Url, tc.Active " +
                        "	From tbl_LeftMenu tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_LeftMenu WHERE MenuID=@MenuID) + '%' " +
                         OrderBy +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable LeftMenu_GetListByUserName(string UserName)
        {
            string Query = "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        " From tbl_LeftMenu tc JOIN tbl_LeftMenuGroup lmg ON tc.MenuID=lmg.MenuID " +
                        " Where lmg.GroupID IN(select g.GroupID from tbl_Manager m JOIN tbl_GroupUser g ON m.UserName = g.UserName " +
                        " where m.UserName=@UserName) " +
                        "	Order By tc.Depth  ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = UserName;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable LeftMenu_ViewItemByMenuID(int MenuID)
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url,  " +
                        "	Case Target When 1 Then '_blank' " +
                        "		When 0 Then '_self' END As _Target, SortIndex, " +
                        "	Case Active When 1 Then N'Có' " +
                        "	When 0 Then N'Không' END As _Active From tbl_LeftMenu " +
                        "	Where MenuID=@MenuID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string LeftMenu_GetParentNameByMenuID(int ParentID)
        {
            string Query = "Select Title From tbl_LeftMenu " +
                        "	Where MenuID=@ParentID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        public DataTable LeftMenu_Search(int MenuID, string Keyword)
        {
            string Query = " Select MenuID, ParentID,  " +
                        "	Case Decen  " +
                        "		When 0 Then Title " +
                        "		When 1 Then ':: '+ Title " +
                        "		When 2 Then ':: :: ' + Title " +
                        "		When 3 Then ':: :: :: ' + Title " +
                        "		When 4 Then ':: :: :: :: ' + Title " +
                        "	End " +
                        "	As _Title, " +
                        "	Title, Decen, Depth, Description, Url, Target, SortIndex, Active, " +
                        "    Case Active " +
                        "		   When 1 Then N'Có' " +
                        "		   When 0 Then N'Không'  " +
                        "	END As _Active " +
                        "	From tbl_LeftMenu where 1=1 ";
            if (MenuID > 0)
                Query += " And Depth LIKE(Select Depth From tbl_LeftMenu " +
                        "		Where tbl_LeftMenu.MenuID=@MenuID)+'%' ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And(Title like N'%'+@Keyword+'%' Or Description like N'%'+@Keyword+'%' Or Url like N'%'+@Keyword+'%') ";
            Query += " Order by Depth ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int),
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = MenuID;
            arrParam[1].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable LeftMenu_GetTree(int MenuID)
        {
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Description, tc.Url, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Target, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_LeftMenu tc  " +
                        "	 " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Description, " +
                        "	   tc.Url, tc.Target, tc.SortIndex, tc.Active " +
                        "	From tbl_LeftMenu tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_LeftMenu WHERE MenuID=@MenuID) + '%' " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void LeftMenu_InsertItem(int ParentID, string Title, string Description, string Url, int Target, int SortIndex, int Active)
        {
            string Query = "Insert Into tbl_LeftMenu( " +
                        "ParentID,Title,Description,Url,Target,SortIndex,Active) " +
                        "Values(@ParentID,@Title,@Description,@Url,@Target,@SortIndex,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),
                    new SqlParameter("@Target", SqlDbType.Int),
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Description;
            arrParam[3].Value = Url;
            arrParam[4].Value = Target;
            arrParam[5].Value = SortIndex;
            arrParam[6].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void LeftMenu_UpDateItem(int MenuID, int ParentID, string Title, string Description, string Url, int Target, int SortIndex, int Active)
        {
            string Query = "Update tbl_LeftMenu " +
                        "Set " +
                        "	ParentID=@ParentID, " +
                        "	Title=@Title, " +
                        "	Description=@Description, " +
                        "	Url=@Url, " +
                        "	Target=@Target,	 " +
                        "	SortIndex=@SortIndex, " +
                        "	Active=@Active " +
                        "Where MenuID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int),
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),
                    new SqlParameter("@Target", SqlDbType.Int),
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            arrParam[1].Value = ParentID;
            arrParam[2].Value = Title;
            arrParam[3].Value = Description;
            arrParam[4].Value = Url;
            arrParam[5].Value = Target;
            arrParam[6].Value = SortIndex;
            arrParam[7].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void LeftMenu_DeleteItem(int MenuID)
        {
            string Query = "Delete From tbl_LeftMenu" +
                        " Where MenuID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string LeftMenu_GetTitle(int MenuID)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_LeftMenu" +
                        " Where MenuID=@MenuID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable LeftMenu_GetItemRoot()
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url, Target From tbl_LeftMenu" +
                        " Where Active = 1 and ParentID = 0" +
                        " Order By SortIndex";

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable LeftMenu_GetItemRootByUserName(string UserName)
        {
            string Query = "Select DISTINCT lm.MenuID, lm.ParentID, lm.Title, lm.Description, lm.Url, lm.Target, lm.SortIndex From tbl_LeftMenu lm JOIN tbl_LeftMenuGroup lmg ON lm.MenuID=lmg.MenuID " +
            "Where lm.Active = 1 and lm.ParentID = 0 and lmg.GroupID IN (select g.GroupID from tbl_Manager m JOIN tbl_GroupUser g ON m.UserName = g.UserName " +
            "where m.UserName=@UserName) " +
            " Order By lm.SortIndex";
            SqlParameter[] arrParam ={
		        new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = UserName;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable LeftMenu_GetItemByParentID(int Parent)
        {
            string Query = "Select MenuID, ParentID, Title, Description, Url, Target From tbl_LeftMenu" +
                        " Where Active = 1 and ParentID=@Parent" +
                        " Order By SortIndex";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Parent", SqlDbType.Int)};
            arrParam[0].Value = Parent;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable LeftMenu_GetItemByParentIDAndUserName(int Parent, string UserName)
        {
            string Query = "Select DISTINCT lm.MenuID, lm.ParentID, lm.Title, lm.Description, lm.Url, lm.Target, lm.SortIndex From tbl_LeftMenu lm JOIN tbl_LeftMenuGroup lmg ON lm.MenuID=lmg.MenuID " +
            "Where lm.Active = 1 and lm.ParentID = @Parent and lmg.GroupID IN(select g.GroupID from tbl_Manager m JOIN tbl_GroupUser g ON m.UserName = g.UserName " +
            "where m.UserName=@UserName) " +
            " Order By lm.SortIndex";
            SqlParameter[] arrParam ={                    
		        new SqlParameter("@Parent", SqlDbType.Int),
		        new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = Parent;
            arrParam[1].Value = UserName;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        #endregion
        //ok
        #region Ajax - Function
        //[AjaxPro.AjaxMethod]
        //public string DeleteItemFromTableByID(string tblName, string KeyField, string ParentField, string ItemID, string datatype)
        //{
        //    string Value = string.Empty;
        //    try
        //    {
        //        if (!string.IsNullOrEmpty(ParentField))
        //        {
        //            if (CountSubItem(int.Parse(ItemID),KeyField,ParentField,tblName) > 0)
        //                return "ERROR: Cần xóa submenu trước khi thực hiện xóa menu này!";
        //        }
        //        string Query = "delete from " + tblName.Trim() + " where " + KeyField.Trim() + "=@ItemID";
        //        if (datatype.Equals("1"))
        //        {
        //            SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //            arrParam[0].Value = new Guid(ItemID);
        //            DB.ExeCuteSqlParam(Query, arrParam);
        //        }
        //        else if (datatype.Equals("2"))
        //        {
        //            SqlParameter[] arrParam ={
        //                new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
        //            arrParam[0].Value = int.Parse(ItemID);
        //            DB.ExeCuteSqlParam(Query, arrParam);
        //        }
        //        else
        //        { 
        //            SqlParameter[] arrParam ={
        //                new SqlParameter("@ItemID", SqlDbType.VarChar)};
        //            arrParam[0].Value = ItemID;
        //            DB.ExeCuteSqlParam(Query, arrParam);
        //        }              
        //    }
        //    catch (Exception ex)
        //    {
        //        Value = "ERROR: " + ex.Message;
        //    }
        //    return Value;
        //}
        //[AjaxPro.AjaxMethod]
        //public string ViewCountProductInCart()
        //{
        //    DataTable dt = (DataTable)System.Web.HttpContext.Current.Session["cart"];
        //    //double totalmoney = 0;
        //    int countproduct = 0;
        //    if (dt.Rows.Count > 0)
        //    {
        //        foreach (DataRow dr in dt.Rows) //lay tat ca gia tri trong bang
        //        {
        //            countproduct += int.Parse(dr[3].ToString());
        //            //totalmoney += double.Parse(dr[4].ToString());
        //        }
        //    }
        //    return "Giỏ hàng(" + countproduct.ToString() + " sản phẩm)";
        //}


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string DeleteItemFromTableByID(string tblName, string KeyField, string ParentField, string ItemID, string datatype)
        {
            string Value = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(ParentField))
                {
                    if (CountSubItem(int.Parse(ItemID), KeyField, ParentField, tblName) > 0)
                        return "ERROR: Cần xóa submenu trước khi thực hiện xóa menu này!";
                }
                string Query = "delete from " + tblName.Trim() + " where " + KeyField.Trim() + "=@ItemID";

                if (datatype.Equals("0"))
                {
                    SqlParameter[] arrParam ={                    
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
                    arrParam[0].Value = ItemID;
                    DB.ExeCuteSqlParam(Query, arrParam);
                }

                if (datatype.Equals("1"))
                {
                    SqlParameter[] arrParam ={
                    //new SqlParameter("@ItemID", SqlDbType.Int)};
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
                    arrParam[0].Value = int.Parse(ItemID);
                    DB.ExeCuteSqlParam(Query, arrParam);
                }
                else if (datatype.Equals("2"))
                {
                    SqlParameter[] arrParam ={
                        new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
                    arrParam[0].Value = new Guid(ItemID);
                    DB.ExeCuteSqlParam(Query, arrParam);
                }
                else
                {
                    SqlParameter[] arrParam ={
                        new SqlParameter("@ItemID", SqlDbType.VarChar)};
                    arrParam[0].Value = ItemID;
                    DB.ExeCuteSqlParam(Query, arrParam);
                }
            }
            catch (Exception ex)
            {
                Value = "ERROR: " + ex.Message;
            }
            return Value;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string DeleteProductByID(string ItemID)
        {
            string Value = string.Empty;
            try
            {
                string Query = "delete from tbl_Products where  ProductID=@ItemID ";

                SqlParameter[] arrParam ={                    
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
                arrParam[0].Value = ItemID;
                DB.ExeCuteSqlParam(Query, arrParam);

            }
            catch (Exception ex)
            {
                Value = "ERROR: " + ex.Message;
            }
            return Value;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string DeleteItemFromTableByIDWithString(string tblName, string KeyField, string ParentField, string ItemID, string datatype)
        {
            string Value = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(ParentField))
                {
                    if (CountSubItem(int.Parse(ItemID), KeyField, ParentField, tblName) > 0)
                        return "ERROR: Cần xóa submenu trước khi thực hiện xóa menu này!";
                }
                string Query = "delete from " + tblName.Trim() + " where " + KeyField.Trim() + "=@ItemID";
                if (datatype.Equals("1"))
                {
                    SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
                    arrParam[0].Value = int.Parse(ItemID);
                    DB.ExeCuteSqlParam(Query, arrParam);
                }
                else if (datatype.Equals("2"))
                {
                    SqlParameter[] arrParam ={
                        new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
                    arrParam[0].Value = new Guid(ItemID);
                    DB.ExeCuteSqlParam(Query, arrParam);
                }
                else
                {
                    SqlParameter[] arrParam ={
                        new SqlParameter("@ItemID", SqlDbType.VarChar)};
                    arrParam[0].Value = ItemID;
                    DB.ExeCuteSqlParam(Query, arrParam);
                }
            }
            catch (Exception ex)
            {
                Value = "ERROR: " + ex.Message;
            }
            return Value;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string DeleteItemFromTableGroupUser(string groupid, string username)
        {
            string Value = string.Empty;
            try
            {
                string Query = "delete from tbl_GroupUser " +
                            " where GroupID=@GroupID and UserName=@UserName ";

                SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
                arrParam[0].Value = new Guid(groupid);
                arrParam[1].Value = username;
                DB.ExeCuteSqlParam(Query, arrParam);
            }
            catch (Exception ex)
            {
                Value = "ERROR: " + ex.Message;
            }
            return Value;
        }
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string ViewCountProductInCart()
        {
            DataTable dt = (DataTable)System.Web.HttpContext.Current.Session["cart"];
            //double totalmoney = 0;
            int countproduct = 0;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows) //lay tat ca gia tri trong bang
                {
                    countproduct += int.Parse(dr[3].ToString());
                    //totalmoney += double.Parse(dr[4].ToString());
                }
            }
            return "My cart(" + countproduct.ToString() + " products)";
        }

        [AjaxPro.AjaxMethod()]
        public string AddCardOrder1(string loginName, string bodyVal)
        {
            string Value = string.Empty;
            string QueryUser = "Select Top 1 CustommerID, FullName, PhoneNumber, Address, Email,PhoneNumber From tbl_Custommers " +
                        " Where Active = 1 and LoginName=@LoginName";
            DataTable dtCustomer = new DataTable();
            SqlParameter[] arrParam1 ={
                    new SqlParameter("@LoginName", SqlDbType.VarChar, 150)};

            arrParam1[0].Value = loginName;
            dtCustomer = DB.ViewTableParam(QueryUser, arrParam1);

            // Insert to order table

            try
            {
                string Query = "Insert Into tbl_CartOrder( " +
                             "   [Title] \n" +
                             "  ,[Body] \n" +
                             "  ,[Created] \n" +
                             "  ,[Sender] \n" +
                             "  ,[Email] \n" +
                             "  ,[Phone]) \n" +

                             " Values( \n" +
                             " @Title, \n" +
                             " @Body, \n" +
                             " @Created, \n" +
                             " @name, \n" +
                             " @email, \n" +
                             " @phone ) ;" +

                "INSERT INTO [DBShoppingCart_New].[dbo].[tbl_Order] \n" +
                            "           ([OrderID] \n" +
                            "           ,[CustommerID] \n" +
                            "           ,[PaymentMethodID] \n" +
                            "           ,[Comment] \n" +
                            "           ,[AdminComment] \n" +
                            "           ,[Created] \n" +
                            "           ,[StatusOrderID]) \n" +

                            " Values( \n" +
                                        " @OrderID, \n" +
                                        " @CustommerID, \n" +
                                        " @PaymentMethodID, \n" +
                                        " @Comment, \n" +
                                        " @AdminComment, \n" +
                                        " @Created," +
                                        " @StatusOrderID)";


                SqlParameter[] arrParam ={
                    new SqlParameter("@Title", SqlDbType.NVarChar, 150),
                    new SqlParameter("@Body", SqlDbType.NVarChar, 4000),
                    new SqlParameter("@Created", SqlDbType.SmallDateTime),
                    new SqlParameter("@name", SqlDbType.NVarChar,150),
                    new SqlParameter("@email", SqlDbType.NVarChar, 100),
                    new SqlParameter("@phone", SqlDbType.VarChar,20),

                    new SqlParameter("@OrderID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@CustommerID", SqlDbType.VarChar,36),
                    new SqlParameter("@PaymentMethodID", SqlDbType.VarChar),
                    new SqlParameter("@Comment", SqlDbType.NVarChar,300),
                    new SqlParameter("@AdminComment", SqlDbType.NVarChar, 300),            
                    new SqlParameter("@StatusOrderID", SqlDbType.SmallInt)};


                arrParam[0].Value = "Order_" + DateTime.Now.ToString("yyyy-MM-dd");
                arrParam[1].Value = bodyVal;
                arrParam[2].Value = DateTime.Now;
                arrParam[3].Value = dtCustomer.Rows[0]["FullName"];
                arrParam[4].Value = dtCustomer.Rows[0]["Email"];
                arrParam[5].Value = dtCustomer.Rows[0]["PhoneNumber"];


                string CustomerId = dtCustomer.Rows[0]["CustommerId"].ToString();
                Guid OrderId = System.Guid.NewGuid();

                arrParam[6].Value = OrderId;
                arrParam[7].Value = CustomerId;
                arrParam[8].Value = PaymentMethodID;
                arrParam[9].Value = "Order created!";
                arrParam[10].Value = "";
                arrParam[11].Value = 1;

                DB.ExeCuteSqlParam(Query, arrParam);

                // then insert to orderdetail table
                if (dtCart != null)
                {
                    for (int i = 0; i < dtCart.Rows.Count; i++)
                    {
                        string productCode = dtCart.Rows[i]["ProductID"].ToString();
                        string productName = dtCart.Rows[i]["ProductName"].ToString();
                        int itemnumber = Convert.ToInt16(dtCart.Rows[i]["ItemNumber"]);
                        double price = Convert.ToDouble(dtCart.Rows[i]["NewPrice"]);
                        InsertOrderAndOrderDetail(CustomerId, productCode, itemnumber, price, OrderId, productName);
                    }
                }
                HttpContext.Current.Session["Cart"] = null;
                dtCart = null;
            }
            catch (Exception ex)
            {
                Value = "ERROR: " + ex.Message.ToString();
            }
            return Value;
        }

        private void InsertOrderAndOrderDetail(string CustomerId, string productCode, int Quantity, double price, Guid OrderId, string ProductName)
        {


            string Query =
            "INSERT INTO [DBShoppingCart_New].[dbo].[tbl_OrderDetail] \n" +
            "           ([OrderDetailID] \n" +
            "           ,[OrderID] \n" +
            "           ,[ProductID] \n" +
            "           ,[Quantity] \n" +
            "           ,[Price] \n" +
            "          ,[TotalMoney]" +
            "          ,[ProductName]) \n" +

              " Values( \n" +
                         " @OrderDetailID, \n" +
                         " @OrderID, \n" +
                         " @ProductID, \n" +
                         " @Quantity, \n" +
                         " @Price, \n" +
                         " @TotalMoney, " +
                         " @ProductName) ;";


            SqlParameter[] arrParamOrder ={
                    new SqlParameter("@OrderID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@OrderDetailID", SqlDbType.UniqueIdentifier),                   
                    new SqlParameter("@ProductID", SqlDbType.VarChar,50),
                    new SqlParameter("@Quantity", SqlDbType.SmallInt),
                    new SqlParameter("@Price", SqlDbType.Float),
                    new SqlParameter("@TotalMoney", SqlDbType.Float),
                    new SqlParameter("@ProductName", SqlDbType.NVarChar,300)};


            arrParamOrder[0].Value = OrderId;          
            arrParamOrder[1].Value = System.Guid.NewGuid();
            arrParamOrder[2].Value = productCode;
            arrParamOrder[3].Value = Quantity;
            arrParamOrder[4].Value = price;
            arrParamOrder[5].Value = (Quantity * price);
            arrParamOrder[6].Value = ProductName;

            DB.ExeCuteSqlParam(Query, arrParamOrder);

        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string AddCardOrder(string Body, string nameVal, string emailVal, string phoneVal)
        {
            string Value = string.Empty;
            try
            {
                KhachHang_BLL CustomerBll = new KhachHang_BLL();
                DateTime defaultBirth = DateTime.Parse("1/1/" + (DateTime.Now.Year - 20));
                bool isExits = CustomerBll.CheckExitsUser(emailVal, phoneVal);                
                string loginName = phoneVal;
                if (!isExits)
                {
                    CustomerBll.AddNewCustomer(1,loginName, phoneVal, emailVal, nameVal, phoneVal, "", "Nam", defaultBirth, string.Empty, DateTime.Now, 1,0,ref Value);                 
                }
                else {
                    loginName = emailVal.Split('@')[0];

                    CustomerBll.AddNewCustomer(1, loginName, loginName, emailVal, nameVal, phoneVal, "", "Nam", defaultBirth, string.Empty, DateTime.Now, 1,0,ref Value);
                }
                if (Value.IndexOf("ERROR") != -1)
                {
                    return "ERROR: Duplace key!";
                }
                else
                {
                    HttpContext.Current.Session["Khach"] = loginName;
                    AddCardOrder1(loginName, Body);
                }
            }
            catch (Exception ex) {
                Value = "ERROR: " + ex.Message;
            }
            return Value;
        }
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string CheckSessionCart()
        {
            if (HttpContext.Current.Session["Cart"] != null)
                return "1";
            else return "0";
        }
        public int CountSubItem(int MenuID, string KeyField, string ParentField, string tblName)
        {
            string Query = "Select Count(*) as SL From " + tblName + "" +
                        " Where " + ParentField + "=@" + KeyField + "";
            SqlParameter[] arrParam ={
                    new SqlParameter("@"+KeyField+"", SqlDbType.Int)};
            arrParam[0].Value = MenuID;
            return int.Parse(DB.ExeCuteScalarParam(Query, arrParam));
        }
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string GetCurrentDateTime()
        {
            return DateTime.Now.ToString();
        }
        #endregion
        //ok
        #region TableBanner - GetData
        public DataTable Banner_GetTop1Item()
        {
            string Query = "Select Top 1 FileName, FileType From tbl_Banner" +
                        " Where Active = 1" +
                        " Order By Modified Desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Banner_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "Order By Modified desc ";
            string Query = "Select BannerID, Title, FileName, FileType, Created, Modified, Active,  " +
                        "Case Active " +
                        "When 1 Then N'Có' " +
                        "When 0 Then N'Không'  " +
                        "End as _Active From tbl_Banner " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Banner_ViewItemByItemID(int ItemID)
        {
            string Query = "Select BannerID, Title, FileName, FileType, Created, Modified, Active,  " +
                        "Case Active " +
                        "When 1 Then N'Có' " +
                        "When 0 Then N'Không'  " +
                        "End as _Active From tbl_Banner " +
                        "	Where BannerID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Banner_InsertItem(string Title, string FileName, string FileType, int Active, DateTime Created, DateTime Modified)
        {
            string Query = "Insert Into tbl_Banner( " +
                        "Title,FileName,FileType,Active,Created,Modified) " +
                        "Values(@Title,@FileName,@FileType,@Active,@Created,@Modified) ";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@FileName", SqlDbType.NVarChar),
                    new SqlParameter("@FileType", SqlDbType.NVarChar),
                    new SqlParameter("@Active", SqlDbType.Int),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime)};
            arrParam[0].Value = Title;
            arrParam[1].Value = FileName;
            arrParam[2].Value = FileType;
            arrParam[3].Value = Active;
            arrParam[4].Value = Created;
            arrParam[5].Value = Modified;
            DB.ExeCuteSqlParam(Query, arrParam);
        }

        public string Banner_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_Banner" +
                        " Where BannerID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public void Banner_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_Banner" +
                        " Where BannerID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Banner_UpDateItem(int BannerID, string Title, string FileName, string FileType, int Active, DateTime Modified)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(FileName))
            {
                Query = "Update tbl_Banner " +
                        "Set " +
                        "	Title=@Title, " +
                        "	FileName=@FileName, " +
                        "	FileType=@FileType, " +
                        "	Active=@Active, " +
                        "	Modified=@Modified " +
                        "Where BannerID=@BanerID";
            }
            else
            {
                Query = "Update tbl_Banner " +
                        "Set " +
                        "	Title=@Title, " +
                        "	FileType=@FileType, " +
                        "	Active=@Active, " +
                        "	Modified=@Modified	 " +
                        "Where BannerID=@BanerID";
            }
            SqlParameter[] arrParam ={
                    new SqlParameter("@BanerID", SqlDbType.Int),                 
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@FileName", SqlDbType.NVarChar),
                    new SqlParameter("@FileType", SqlDbType.NVarChar),
                    new SqlParameter("@Active", SqlDbType.Int),
                    new SqlParameter("@Modified", SqlDbType.DateTime)};
            arrParam[0].Value = BannerID;
            arrParam[1].Value = Title;
            arrParam[2].Value = FileName;
            arrParam[3].Value = FileType;
            arrParam[4].Value = Active;
            arrParam[5].Value = Modified;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion

        //ok
        #region TableProducts - GetData
        //public DataTable ReadingMenuKhuyenMai()
        //{
        //    string Query = "Select Title, Description, Url, Target  From tbl_Menu" +
        //                "	Where Active = 1 and Location=3" +
        //                "	Order By SortIndex";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public DataTable ReadingMenuNewProducts()
        //{
        //    string Query = "Select Title, Description, Url, Target  From tbl_Menu" +
        //                "	Where Active = 1 and Location=4" +
        //                "	Order By SortIndex";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}

        public DataTable ReadingProductsByCat(string catid, ref string catname)
        {
            string Query = "Select Top 12 p.ProductID, p.CateID, p.ProductName, p.Description, p.Image, p.OldPrice, p.NewPrice, p.Status, p.KhuyenMai, c.Title From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID" +
                        " Where p.Active=1 and p.Cateid= @catid " +
                        " Order By Created desc";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@catid", SqlDbType.NVarChar)};
            arrParam[0].Value = catid;

            DataTable dtResult = DB.ViewTableParam(Query, arrParam);

            if (dtResult.Rows.Count > 0)
                catname = dtResult.Rows[0]["Title"].ToString();
            return dtResult;
        }

        public DataTable Products_SellerReading()
        {
            string Query = "Select Top 15 ProductID, CateID, ProductName, Description, Image, OldPrice, NewPrice From tbl_Products" +
                        " Where Active=1 and SPBanChay=1" +
                        " Order By Modified desc, Created desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Products_KhuyenMaiReading()
        {
            string Query = "Select Top 12 p.ProductID, p.CateID, p.ProductName, p.Description, p.Image, p.OldPrice, p.NewPrice, p.Status, p.KhuyenMai, c.Title From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID" +
                        " Where p.Active=1 and p.SPKhuyenMai=1" +
                        " Order By Modified desc, Created desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable GetProducts_KhuyenMaiReading(string CateID)
        {
            string Query = "Select Top 12 p.ProductID, p.CateID, p.ProductName, p.Description, p.Image, p.OldPrice, p.NewPrice, p.Status, p.KhuyenMai, c.Title From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID" +
                        " Where p.Active=1 and p.SPKhuyenMai=1 and p.CateID in (select CateID from tbl_Category where ParentID = @CateID) " +
                        " Order By Modified desc, Created desc";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);

            return dtResult;
        }
        public DataTable Products_NewReading()
        {
            string Query = "Select Top 12 p.ProductID, p.CateID, p.ProductName, p.Description, p.Image, p.OldPrice, p.NewPrice, p.Status, p.KhuyenMai, c.Title From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID" +
                        " Where p.Active=1 and IsNew = 1 " +
                        " Order By Created desc, Modified desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }

        public DataTable BuildProducts_NewReading(string CateID)
        {
            string Query = "Select Top 12 p.ProductID, p.CateID, p.ProductName, p.Description, p.Image, p.OldPrice, p.NewPrice, p.Status, p.KhuyenMai, c.Title From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID" +
                        " Where p.Active=1 and p.CateID in (select CateID from tbl_Category where ParentID = @CateID) " +
                        " Order By Created desc, Modified desc";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);

            return dtResult;
        }

        public DataTable Products_ListSPCungLoai(string ProductID, int CateID)
        {
            string Query = "Select Top 12 p.ProductID, p.CateID, p.ProductName, p.Description, p.Image, p.OldPrice, p.NewPrice, p.Status, p.KhuyenMai, c.Title From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID " +
                        "Where p.Active=1 and p.ProductID<>@ProductID ";
            if (CateID > 0)
                Query += " and (Depth LIKE(Select dm.Depth From tbl_Category dm  " +
                        "    Where dm.CateID=cast(@CateID as varchar(10)))+'%') ";
            Query += "Order By Created desc, Modified desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar),                   
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = ProductID;
            arrParam[1].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Products_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("p", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "Order By p.Modified desc, p.CountView desc ";
            string Query = "Select p.ProductID, p.CateID, c.Title, p.BrandID, b.BrandName, " +
                        "	   p.ProductName, p.Description,p.Body,p.Image,p.OtherImage,p.OldPrice,p.NewPrice, " +
                        "	   p.Created,p.Modified,p.CountView,p.BaoHanh,p.KhuyenMai,p.SPKhuyenMai, " +
                        "	   Case p.SPKhuyenMai When 0 Then N'No' When 1 Then N'Yes' End as _SPKhuyenMai, p.SPBanChay, " +
                        "	   Case p.SPBanChay When 0 Then N'No' When 1 Then N'Yes' End as _SPBanChay, p.Status, " +
                        "	   Case p.IsNew When 0 Then N'No' When 1 Then N'Yes' End as IsNew, " +
                        "	   Case p.Status When 0 Then N'Out of stock' When 1 Then N'Stocking' End as _Status, p.Active, " +
                        "	   Case p.Active When 0 Then N'No' When 1 Then N'Yes' End as _Active, " +
                        "      (cast((select COUNT(*) from tbl_CommentProduct where ProductID=p.ProductID) as varchar(50))+' - <font color=''red''>'+ " +
                        "      cast((select COUNT(*) from tbl_CommentProduct where ProductID=p.ProductID and Active = 0) as varchar(50))+'</font>') as Comment " +
                        " From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID LEFT JOIN tbl_Brands b ON p.BrandID = b.BrandID Where p.Active=1 " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Products_GetItemsByCateID(int CateID, string SortValue)
        {
            string Query = "Select p.ProductID, p.CateID, c.Title, p.BrandID, b.BrandName, " +
                        "	   p.ProductName, p.Description,p.Body,p.Image,p.OtherImage,p.OldPrice,p.NewPrice, " +
                        "	   p.Created,p.Modified,p.CountView,p.BaoHanh,p.KhuyenMai,p.SPKhuyenMai, " +
                        "	   Case p.SPKhuyenMai When 0 Then N'Không' When 1 Then N'Có' End as _SPKhuyenMai, p.SPBanChay, " +
                        "	   Case p.SPBanChay When 0 Then N'Không' When 1 Then N'Có' End as _SPBanChay, p.Status, " +
                        "	   Case p.Status When 0 Then N'Hết hàng' When 1 Then N'Còn hàng' End as _Status, p.Active, " +
                        "	   Case p.Active When 0 Then N'Không' When 1 Then N'Có' End as _Active " +
                        " From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID LEFT JOIN tbl_Brands b ON p.BrandID = b.BrandID " +
                        " Where c.Depth LIKE(Select Depth From tbl_Category " +
                        " Where CateID=@CateID and p.Active=1)+'%' " +
                        " Order By " + GetSortByValue("p", SortValue) + " p.Modified desc, p.CountView desc ";
            SqlParameter[] arrParam ={                
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Products_ViewItemByID(string ItemID)
        {
            string Query = "Select p.ProductID,p.IsNew, p.CateID, c.Title, p.BrandID, b.BrandName, " +
                        "	   p.ProductName, p.Description,p.Body,p.Image,p.OtherImage,p.OldPrice,p.NewPrice, " +
                        "	   p.Created,p.Modified,p.CountView,p.BaoHanh,p.KhuyenMai,p.SPKhuyenMai, p.IsNew , " +
                        "	   Case p.SPKhuyenMai When 0 Then N'Yes' When 1 Then N'No' End as _SPKhuyenMai, p.SPBanChay, " +
                        "	   Case p.SPBanChay When 0 Then N'Yes' When 1 Then N'No' End as _SPBanChay, p.Status, " +

                        "	   Case p.IsNew When 0 Then N'No' When 1 Then N'Yes' End as IsNew," +

                        "	   Case p.Status When 0 Then N'Stocking' When 1 Then N'Out of stocking' End as _Status, p.Active, " +
                        "	   Case p.Active When 0 Then N'Active' When 1 Then N'DeActive' End as _Active " +
                        "From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID LEFT JOIN tbl_Brands b ON p.BrandID = b.BrandID " +
                        "	Where ProductID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string Products_ViewFieldImageByID(string ItemID)
        {
            string RetValue = string.Empty;
            string Query = "Select Image From tbl_Products " +
                        "	Where ProductID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            RetValue = DB.ExeCuteScalarParam(Query, arrParam);
            return RetValue;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string Products_DeleteItem(string ItemID)
        {
            string reV = string.Empty;
            try
            {
                string Query =

                     " Update tbl_Order set StatusOrderID = 5 where  OrderID in " +
                        " (select OrderID from tbl_OrderDetail where ProductID = @ItemID ) ;" +

                        " Delete from tbl_OrderDetail where ProductID in " +
                        " (select ProductId from tbl_Products where ProductID = @ItemID ) ;" +

                        " Delete from tbl_OrderDetail where ProductID in " +
                        " (select ProductId from tbl_Products where ProductID = @ItemID ) ;" +


                        " Delete From tbl_Products " +
                                " Where ProductID=@ItemID ;";

                SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
                arrParam[0].Value = ItemID;
                DB.ExeCuteSqlParam(Query, arrParam);
            }
            catch (Exception ex) {
                reV = "ERROR: " + ex.Message;
            }
            return reV;
        }


    
        public string Products_GetTitle(string itemid)
        {
            string Value = string.Empty;
            string Query = "Select ProductName From tbl_Products" +
                        " Where ProductID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Products_GetTotalProductByCate(int CateID)
        {
            string Value = string.Empty;
            string Query = "Select Count(*) From tbl_Products" +
                        " Where CateID=@CateID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Products_GetBody(string itemid)
        {
            string Value = string.Empty;
            string Query = "Select Body From tbl_Products" +
                        " Where ProductID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Products_GetCateIDByProductID(string itemid)
        {
            string Value = string.Empty;
            string Query = "Select CateID From tbl_Products" +
                        " Where ProductID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Products_CheckProductID(string porductid)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_Products " +
                           "Where LOWER(ProductID)=LOWER(@ProductID) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar)};
            arrParam[0].Value = porductid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Products_Search(int CateID, string Keyword)
        {
            string Query = " Select p.ProductID, p.CateID, c.Title, p.BrandID, b.BrandName, " +
                        "	   p.ProductName, p.Description,p.Body,p.Image,p.OtherImage,p.OldPrice,p.NewPrice, " +
                        "	   p.Created,p.Modified,p.CountView,p.BaoHanh,p.KhuyenMai,p.SPKhuyenMai, " +
                        "	   Case p.SPKhuyenMai When 0 Then N'Không' When 1 Then N'Có' End as _SPKhuyenMai, p.SPBanChay, " +
                        "	   Case p.SPBanChay When 0 Then N'Không' When 1 Then N'Có' End as _SPBanChay, p.Status, " +
                        "	   Case p.Status When 0 Then N'Hết hàng' When 1 Then N'Còn hàng' End as _Status, p.Active, " +
                        "	   Case p.Active When 0 Then N'Không' When 1 Then N'Có' End as _Active, " +
                        "      (cast((select COUNT(*) from tbl_CommentProduct where ProductID=p.ProductID) as varchar(50))+' - <font color=''red''>'+ " +
                        "      cast((select COUNT(*) from tbl_CommentProduct where ProductID=p.ProductID and Active = 0) as varchar(50))+'</font>') as Comment " +
                        " From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID LEFT JOIN tbl_Brands b ON p.BrandID = b.BrandID " +
                        "   where 1=1 ";
            if (CateID > 0)
                Query += " And Depth LIKE(Select Depth From tbl_Category " +
                        "		Where tbl_Category.CateID=@CateID) +'%' ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And(p.ProductName like N'%'+@Keyword+'%' Or b.BrandName like N'%'+@Keyword+'%' " +
                 "           Or p.Description like N'%'+@Keyword+'%' Or p.Body like N'%'+@Keyword+'%' Or p.BaoHanh like N'%'+@Keyword+'%' Or p.KhuyenMai like N'%'+@Keyword+'%') ";
            Query += " Order By p.Modified desc, p.CountView desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),                   
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Products_Search(string Keyword, string SortValue)
        {
            string Query = " Select p.ProductID, p.CateID, c.Title, p.BrandID, b.BrandName, " +
                        "	   p.ProductName, p.Description,p.Body,p.Image,p.OtherImage,p.OldPrice,p.NewPrice, " +
                        "	   p.Created,p.Modified,p.CountView,p.BaoHanh,p.KhuyenMai,p.SPKhuyenMai, " +
                        "	   Case p.SPKhuyenMai When 0 Then N'Không' When 1 Then N'Có' End as _SPKhuyenMai, p.SPBanChay, " +
                        "	   Case p.SPBanChay When 0 Then N'Không' When 1 Then N'Có' End as _SPBanChay, p.Status, " +
                        "	   Case p.Status When 0 Then N'Hết hàng' When 1 Then N'Còn hàng' End as _Status, p.Active, " +
                        "	   Case p.Active When 0 Then N'Không' When 1 Then N'Có' End as _Active " +
                        " From tbl_Products p JOIN tbl_Category c ON p.CateID=c.CateID LEFT JOIN tbl_Brands b ON p.BrandID = b.BrandID " +
                        "   where 1=1 and p.Active=1 ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And(p.ProductName like N'%'+@Keyword+'%' Or b.BrandName like N'%'+@Keyword+'%' " +
                        "           Or p.Description like N'%'+@Keyword+'%' Or p.Body like N'%'+@Keyword+'%' Or p.BaoHanh like N'%'+@Keyword+'%' Or p.KhuyenMai like N'%'+@Keyword+'%') ";
            Query += " Order By " + GetSortByValue("p", SortValue) + " p.Modified desc, p.CountView desc ";
            SqlParameter[] arrParam ={                
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        private string GetSortByValue(string prefix, string SortValue)
        {
            string Value = string.Empty;
            switch (SortValue)
            {
                case "priceasc":
                    Value = " " + prefix + ".NewPrice asc, ";
                    break;
                case "pricedesc":
                    Value = " " + prefix + ".NewPrice desc, ";
                    break;
                case "isseller":
                    Value = " " + prefix + ".SPKhuyenMai desc, ";
                    break;
            }
            return Value;
        }
        public void Products_InsertItem(string ProductID, int CateID, int BrandID, string ProductName, string Description, string Body, string Image, string OtherImage,
                            float OldPrice, float NewPrice, DateTime Created, DateTime Modified, int CountView, string BaoHanh, string KhuyenMai, bool SPKhuyenMai, bool SPBanChay, bool Status, int Active ,bool isNew)
        {
            string Query = "Insert Into tbl_Products(ProductID,CateID,BrandID,ProductName,Description,Body,Image,OtherImage, " +
                            "OldPrice,NewPrice,Created,Modified,CountView,BaoHanh,KhuyenMai,SPKhuyenMai,SPBanChay,Status,Active,IsNew) " +
                            "Values(@ProductID,@CateID,@BrandID,@ProductName,@Description,@Body,@Image,@OtherImage,@OldPrice,@NewPrice, " +
                            "@Created,@Modified,@CountView,@BaoHanh,@KhuyenMai,@SPKhuyenMai,@SPBanChay,@Status,@Active,@IsNew) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar),
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@BrandID", SqlDbType.Int),
                    new SqlParameter("@ProductName", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@OtherImage", SqlDbType.NVarChar),
                    new SqlParameter("@OldPrice", SqlDbType.Float),     
                    new SqlParameter("@NewPrice", SqlDbType.Float),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime),
                    new SqlParameter("@CountView", SqlDbType.Int),
                    new SqlParameter("@BaoHanh", SqlDbType.NVarChar),
                    new SqlParameter("@KhuyenMai", SqlDbType.NVarChar),
                    new SqlParameter("@SPKhuyenMai", SqlDbType.Bit),
                    new SqlParameter("@SPBanChay", SqlDbType.Bit),
                    new SqlParameter("@Status", SqlDbType.Bit),       
                    new SqlParameter("@Active", SqlDbType.Int),                                     
                    new SqlParameter("@IsNew", SqlDbType.Bit)};                                     


            arrParam[0].Value = ProductID;
            arrParam[1].Value = CateID;
            if (BrandID == 0)
                arrParam[2].Value = DBNull.Value;
            else arrParam[2].Value = BrandID;
            arrParam[3].Value = ProductName;
            arrParam[4].Value = Description;
            arrParam[5].Value = Body;
            arrParam[6].Value = Image;
            arrParam[7].Value = OtherImage;
            arrParam[8].Value = OldPrice;
            arrParam[9].Value = NewPrice;
            arrParam[10].Value = Created;
            arrParam[11].Value = Modified;
            arrParam[12].Value = CountView;
            arrParam[13].Value = BaoHanh;
            arrParam[14].Value = KhuyenMai;
            arrParam[15].Value = SPKhuyenMai;
            arrParam[16].Value = SPBanChay;
            arrParam[17].Value = Status;
            arrParam[18].Value = Active;

            arrParam[19].Value = isNew;

            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Products_UpDateItem(string ProductID, int CateID, int BrandID, string ProductName, string Description, string Body, string Image, string OtherImage,
                            float OldPrice, float NewPrice, DateTime Modified, bool IsNew, string BaoHanh, string KhuyenMai, bool SPKhuyenMai, bool SPBanChay, bool Status, int Active)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(Image))
            {
                Query = "Update tbl_Products " +
                        "Set " +
                        "   CateID=@CateID, " +
                        "   BrandID=@BrandID, " +
                        "   ProductName=@ProductName, " +
                        "   Description=@Description, " +
                        "   Body=@Body, " +
                        "   Image=@Image, " +
                        "   OtherImage=@OtherImage, " +
                        "   OldPrice=@OldPrice, " +
                        "   NewPrice=@NewPrice, " +
                        "   Modified=@Modified, " +
                        "   IsNew =@IsNew, " +
                        "   BaoHanh=@BaoHanh, " +
                        "   KhuyenMai=@KhuyenMai, " +
                        "   SPKhuyenMai=@SPKhuyenMai, " +
                        "   SPBanChay=@SPBanChay, " +
                        "   Status=@Status, " +
                        "   Active=@Active " +
                        "Where ProductID=@ProductID";
            }
            else
            {
                Query = "Update tbl_Products " +
                        "Set " +
                        "   CateID=@CateID, " +
                        "   BrandID=@BrandID, " +
                        "   ProductName=@ProductName, " +
                        "   Description=@Description, " +
                        "   Body=@Body, " +
                        "   OtherImage=@OtherImage, " +
                        "   OldPrice=@OldPrice, " +
                        "   NewPrice=@NewPrice, " +
                        "   Modified=@Modified, " +
                        "   IsNew=@IsNew, " +
                        "   BaoHanh=@BaoHanh, " +
                        "   KhuyenMai=@KhuyenMai, " +
                        "   SPKhuyenMai=@SPKhuyenMai, " +
                        "   SPBanChay=@SPBanChay, " +
                        "   Status=@Status, " +
                        "   Active=@Active " +
                        

                        "Where ProductID=@ProductID";
            }
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar),
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@BrandID", SqlDbType.Int),
                    new SqlParameter("@ProductName", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@OtherImage", SqlDbType.NVarChar),
                    new SqlParameter("@OldPrice", SqlDbType.Float),     
                    new SqlParameter("@NewPrice", SqlDbType.Float),                
                    new SqlParameter("@Modified", SqlDbType.DateTime),
                    new SqlParameter("@IsNew", SqlDbType.Bit),
                    new SqlParameter("@BaoHanh", SqlDbType.NVarChar),
                    new SqlParameter("@KhuyenMai", SqlDbType.NVarChar),
                    new SqlParameter("@SPKhuyenMai", SqlDbType.Bit),
                    new SqlParameter("@SPBanChay", SqlDbType.Bit),
                    new SqlParameter("@Status", SqlDbType.Bit),                           
                    new SqlParameter("@Active", SqlDbType.Bit)};

            arrParam[0].Value = ProductID;
            arrParam[1].Value = CateID;
            if (BrandID == 0)
                arrParam[2].Value = DBNull.Value;
            else arrParam[2].Value = BrandID;
            arrParam[3].Value = ProductName;
            arrParam[4].Value = Description;
            arrParam[5].Value = Body;
            arrParam[6].Value = Image;
            arrParam[7].Value = OtherImage;
            arrParam[8].Value = OldPrice;
            arrParam[9].Value = NewPrice;
            arrParam[10].Value = Modified;
            arrParam[11].Value = IsNew;
            arrParam[12].Value = BaoHanh;
            arrParam[13].Value = KhuyenMai;
            arrParam[14].Value = SPKhuyenMai;
            arrParam[15].Value = SPBanChay;
            arrParam[16].Value = Status;
            arrParam[17].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableNews - GetData
        //public DataTable HotNewsReading()
        //{
        //    string Query = "Select Top 10 NewsID, CateID, Title, Created From tbl_News" +
        //                " Where Active=1" +
        //                " Order By Created desc";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public DataTable GetListNews()
        //{
        //    string Query = "Select NewsID, CateID, Title, Description, Body, Author,  " +
        //                "	Image, Created, Modified, Source, Active, " +
        //                "	Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_News " +
        //                "   Order By Modified desc ";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public void DeleteItemFromtblNews(int ItemID)
        //{
        //    string Query = "Delete From tbl_News" +
        //                " Where NewsID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public string tblNewsGetTitle(int itemid)
        //{
        //    string Value = string.Empty;
        //    string Query = "Select Title From tbl_News" +
        //                " Where NewsID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = itemid;
        //    Value = DB.ExeCuteScalarParam(Query, arrParam);
        //    return Value;
        //}
        //public DataTable NewsSearch(int CateID, string Keyword)
        //{
        //    string Query = "Declare @SQL nvarchar(4000), @SQLDK nvarchar(1000), @SQLDK1 nvarchar(1000), @SQLOrder varchar(200) " +
        //                "Set @SQLDK='' " +
        //                "Set @SQLDK1='' " +
        //                "Set @SQL=N'SELECT n.NewsID, n.CateID, n.Title, " +
        //                "    n.Description, n.Body, n.Author, n.Image, n.Created, n.Modified, n. Source, n.Active, " +
        //                "    Case n.Active " +
        //                "		   When 1 Then N''Có'' " +
        //                "		   When 0 Then N''Không'' " +
        //                "	END As _Active		  " +
        //                "	FROM  tbl_GroupNews dm INNER JOIN " +
        //                "	                         tbl_News n ON dm.CateID = n.CateID where ''1''=''1'''	 " +
        //                "	 " +
        //                "	If @CateID>0 " +
        //                "		Set @SQLDK=' And (Depth LIKE(Select dm.Depth From tbl_GroupNews dm " +
        //                "		Where dm.CateID='+cast(@CateID as varchar(10)) +')+''%'')'        " +
        //                "    If @Keyword<>'' " +
        //                "		Set @SQLDK1=' And (n.Title like N''%'+@Keyword+'%'' or n.Description like N''%'+@Keyword+'%''  " +
        //                "						or n.Body like N''%'+@Keyword+'%'' or n.Author like N''%'+@Keyword+'%'' " +
        //                "						or n.Source like N''%'+@Keyword+'%'')' " +
        //                "    Set @SQLOrder='Order by n.Modified desc' " +
        //                "    Exec (@SQL+@SQLDK+@SQLDK1+@SQLOrder) ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@CateID", SqlDbType.Int),
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = CateID;
        //    arrParam[1].Value = Keyword;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void News_InsertItem(int CateID, string Title, string Description, string Body, string Author, string Image, DateTime Created, DateTime Modified, string Source, int Active)
        //{
        //    string Query = "Insert Into tbl_News( " +
        //                "CateID,Title,Description,Body,Author,Image,Created,Modified,Source,Active) " +
        //                "Values(@CateID,@Title,@Description,@Body,@Author,@Image,@Created,@Modified,@Source,@Active) ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@CateID", SqlDbType.Int),
        //            new SqlParameter("@Title", SqlDbType.NVarChar),
        //            new SqlParameter("@Description", SqlDbType.NVarChar),
        //            new SqlParameter("@Body", SqlDbType.NVarChar),
        //            new SqlParameter("@Author", SqlDbType.NVarChar),
        //            new SqlParameter("@Image", SqlDbType.NVarChar),
        //            new SqlParameter("@Created", SqlDbType.DateTime),
        //            new SqlParameter("@Modified", SqlDbType.DateTime),
        //            new SqlParameter("@Source", SqlDbType.NVarChar),                  
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = CateID;
        //    arrParam[1].Value = Title;
        //    arrParam[2].Value = Description;
        //    arrParam[3].Value = Body;
        //    arrParam[4].Value = Author;
        //    arrParam[5].Value = Image;
        //    arrParam[6].Value = Created;
        //    arrParam[7].Value = Modified;
        //    arrParam[8].Value = Source;
        //    arrParam[9].Value = Active;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public DataTable ViewItemNewsByID(int ItemID)
        //{
        //    string Query = "Select NewsID, CateID, Title, Description, Body, Author,  " +
        //                "	Image, Created, Modified, Source, Active, " +
        //                "	Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_News " +
        //                "	Where NewsID=@ItemID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void News_UpDateItem(int NewsID, int CateID, string Title, string Description, string Body, string Author, string Image, DateTime Modified, string Source, int Active)
        //{
        //    string Query = string.Empty;
        //    if (!string.IsNullOrEmpty(Image))
        //    {
        //        Query = "Update tbl_News " +
        //                "Set " +
        //                "	CateID=@CateID, " +
        //                "	Title=@Title, " +
        //                "	Description=@Description, " +
        //                "	Body=@Body, " +
        //                "	Author=@Author, " +
        //                "	Image=@Image, " +
        //                "	Modified=@Modified, " +
        //                "	Source=@Source, " +
        //                "	Active=@Active " +                      
        //                "Where NewsID=@NewsID";
        //    }
        //    else
        //    {
        //        Query = "Update tbl_News " +
        //                "Set " +
        //                "	CateID=@CateID, " +
        //                "	Title=@Title, " +
        //                "	Description=@Description, " +
        //                "	Body=@Body, " +
        //                "	Author=@Author, " +                      
        //                "	Modified=@Modified, " +
        //                "	Source=@Source, " +
        //                "	Active=@Active " +
        //                "Where NewsID=@NewsID";
        //    }
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@NewsID", SqlDbType.Int),   
        //            new SqlParameter("@CateID", SqlDbType.Int),
        //            new SqlParameter("@Title", SqlDbType.NVarChar),
        //            new SqlParameter("@Description", SqlDbType.NVarChar),
        //            new SqlParameter("@Body", SqlDbType.NVarChar),
        //            new SqlParameter("@Author", SqlDbType.NVarChar),
        //            new SqlParameter("@Image", SqlDbType.NVarChar),
        //            new SqlParameter("@Modified", SqlDbType.DateTime),
        //            new SqlParameter("@Source", SqlDbType.NVarChar),                 
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = NewsID;
        //    arrParam[1].Value = CateID;
        //    arrParam[2].Value = Title;
        //    arrParam[3].Value = Description;
        //    arrParam[4].Value = Body;
        //    arrParam[5].Value = Author;
        //    arrParam[6].Value = Image;
        //    arrParam[7].Value = Modified;
        //    arrParam[8].Value = Source;
        //    arrParam[9].Value = Active;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        public DataTable News_GetHotNews()
        {
            string Query = "Select Top 10 NewsID, CateID, Title, Created From tbl_News" +
                        " Where Active=1" +
                        " Order By Created desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable News_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By Modified desc ";
            string Query = "Select NewsID, CateID, Title, Description, Body, Author,  " +
                        "	Image, Created, Modified, Source, Active, " +
                        "	Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_News " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void News_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_News" +
                        " Where NewsID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string News_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_News" +
                        " Where NewsID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable News_Search(int CateID, string Keyword)
        {
            string Query = " SELECT n.NewsID, n.CateID, n.Title, " +
                        "    n.Description, n.Body, n.Author, n.Image, n.Created, n.Modified, n. Source, n.Active, " +
                        "    Case n.Active " +
                        "		   When 1 Then N'Có' " +
                        "		   When 0 Then N'Không' " +
                        "	END As _Active		  " +
                        "	FROM  tbl_GroupNews dm INNER JOIN " +
                        "	                         tbl_News n ON dm.CateID = n.CateID where 1=1 ";
            if (CateID > 0)
                Query += " And (Depth LIKE(Select dm.Depth From tbl_GroupNews dm " +
                        "		Where dm.CateID=@CateID)+'%')  ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And (n.Title like N'%'+@Keyword+'%' or n.Description like N'%'+@Keyword+'%'  " +
                        "						or n.Body like N'%'+@Keyword+'%' or n.Author like N'%'+@Keyword+'%' " +
                        "						or n.Source like N'%'+@Keyword+'%') ";
            Query += " Order by n.Modified desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void News_InsertItem(int CateID, string Title, string Description, string Body, string Author, string Image, DateTime Created, DateTime Modified, string Source, int Active)
        {
            string Query = "Insert Into tbl_News( " +
                        "CateID,Title,Description,Body,Author,Image,Created,Modified,Source,Active) " +
                        "Values(@CateID,@Title,@Description,@Body,@Author,@Image,@Created,@Modified,@Source,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Author", SqlDbType.NVarChar),
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime),
                    new SqlParameter("@Source", SqlDbType.NVarChar),                  
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Description;
            arrParam[3].Value = Body;
            arrParam[4].Value = Author;
            arrParam[5].Value = Image;
            arrParam[6].Value = Created;
            arrParam[7].Value = Modified;
            arrParam[8].Value = Source;
            arrParam[9].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable News_ViewItemByID(int ItemID)
        {
            string Query = "Select NewsID, CateID, Title, Description, Body, Author,  " +
                        "	Image, Created, Modified, Source, Active, " +
                        "	Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_News " +
                        "	Where NewsID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable News_GetItemByCateID(int CateID)
        {
            string Query = "Select NewsID, CateID, Title, Description, Body, Author,  " +
                        "	Image, Created, Modified, Source, Active From tbl_News " +
                        "	Where CateID=@CateID and Active=1 ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable News_GetItemByID(int NewsID, int catid, ref DataTable dtRelate)
        {
            string Query = "select * from tbl_News where NewsID = @NewsID and Active = 1";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@NewsID", SqlDbType.Int)};
            arrParam[0].Value = NewsID;

            string QueryRelate = "select top 100 * from tbl_News where CateID=@catid and Active = 1 " +
                                 "   and NewsID <> @NewsID " +
                                 "   order by Created desc ";
            SqlParameter[] arrParamRelate ={                  
                    new SqlParameter("@NewsID", SqlDbType.Int),
                    new SqlParameter("@catid", SqlDbType.Int)};
            arrParamRelate[0].Value = NewsID;
            arrParamRelate[1].Value = catid;

            DataTable dtResult = DB.ViewTableParam(Query, arrParam);
            dtRelate = DB.ViewTableParam(QueryRelate, arrParamRelate);
            return dtResult;
        }
        public void News_UpDateItem(int NewsID, int CateID, string Title, string Description, string Body, string Author, string Image, DateTime Modified, string Source, int Active)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(Image))
            {
                Query = "Update tbl_News " +
                        "Set " +
                        "	CateID=@CateID, " +
                        "	Title=@Title, " +
                        "	Description=@Description, " +
                        "	Body=@Body, " +
                        "	Image=@Image, " +
                        "	Modified=@Modified, " +
                        "	Source=@Source, " +
                        "	Active=@Active " +
                        "Where NewsID=@NewsID";
            }
            else
            {
                Query = "Update tbl_News " +
                        "Set " +
                        "	CateID=@CateID, " +
                        "	Title=@Title, " +
                        "	Description=@Description, " +
                        "	Body=@Body, " +
                        "	Modified=@Modified, " +
                        "	Source=@Source, " +
                        "	Active=@Active " +
                        "Where NewsID=@NewsID";
            }
            SqlParameter[] arrParam ={
                    new SqlParameter("@NewsID", SqlDbType.Int),   
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Author", SqlDbType.NVarChar),
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@Modified", SqlDbType.DateTime),
                    new SqlParameter("@Source", SqlDbType.NVarChar),                 
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = NewsID;
            arrParam[1].Value = CateID;
            arrParam[2].Value = Title;
            arrParam[3].Value = Description;
            arrParam[4].Value = Body;
            arrParam[5].Value = Author;
            arrParam[6].Value = Image;
            arrParam[7].Value = Modified;
            arrParam[8].Value = Source;
            arrParam[9].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableAdverts - GetData
        //public DataTable GetNewsByID(int NewsID,int catid, ref DataTable dtRelate)
        //{
        //    string Query = "select * from tbl_News where NewsID = @NewsID and Active = 1";
        //    SqlParameter[] arrParam ={                  
        //            new SqlParameter("@NewsID", SqlDbType.Int)};
        //    arrParam[0].Value = NewsID;

        //    string QueryRelate = "select top 100 * from tbl_News where CateID=@catid and Active = 1 " +
        //                         "   and NewsID <> @NewsID " +
        //                         "   order by Created desc ";
        //    SqlParameter[] arrParamRelate ={                  
        //            new SqlParameter("@NewsID", SqlDbType.Int),
        //            new SqlParameter("@catid", SqlDbType.Int)};
        //    arrParamRelate[0].Value = NewsID;
        //    arrParamRelate[1].Value = catid;

        //    DataTable dtResult = DB.ViewTableParam(Query, arrParam);
        //    dtRelate = DB.ViewTableParam(QueryRelate, arrParamRelate);
        //    return dtResult;
        //}
        //public DataTable GetListAdvert()
        //{
        //    string Query = "Select ID, Image, Url, Description, Target,  " +
        //                "Case Target " +
        //                "When 0 Then '_self' " +
        //                "When 1 Then '_blank' " +
        //                "End as _Target, Location, Case Location When 1 Then 'Top' When 2 Then 'Bottom' End as _Location, " +
        //                "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active, Created, Modified From tbl_Advert " +
        //                "Order By Modified desc ";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public DataTable AdvertSearch(string Keyword)
        //{
        //    string Query = "Select ID, Image, Url, Description, Target,  " +
        //                "Case Target " +
        //                "When 0 Then '_self' " +
        //                "When 1 Then '_blank' " +
        //                "End as _Target, Location, Case Location When 1 Then 'Top' When 2 Then 'Bottom' End as _Location, " +
        //                "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active, Created, Modified From tbl_Advert " +
        //                "Where Image like N'%'+@Keyword+'%' or Description like N'%'+@Keyword+'%' " +
        //                "Order By Modified desc ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = Keyword;           
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void DeleteItemFromtblAdvert(int ItemID)
        //{
        //    string Query = "Delete From tbl_Advert" +
        //                " Where ID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public string tblAdvertGetImageName(int itemid)
        //{
        //    string Value = string.Empty;
        //    string Query = "Select Image From tbl_Advert" +
        //                " Where ID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = itemid;
        //    Value = DB.ExeCuteScalarParam(Query, arrParam);
        //    return Value;
        //}
        //public void Advert_InsertItem(string Image, string Url, string Description, int Target, int Location, int SortIndex, int Active, DateTime Created, DateTime Modified)
        //{
        //    string Query = "Insert Into tbl_Advert( " +
        //                "Image,Url,Description,Target,Location,SortIndex,Active,Created,Modified) " +
        //                "Values(@Image,@Url,@Description,@Target,@Location,@SortIndex,@Active,@Created,@Modified) ";
        //    SqlParameter[] arrParam ={                  
        //            new SqlParameter("@Image", SqlDbType.NVarChar),
        //            new SqlParameter("@Url", SqlDbType.NVarChar),
        //            new SqlParameter("@Description", SqlDbType.NVarChar),
        //            new SqlParameter("@Target", SqlDbType.Int),
        //            new SqlParameter("@Location", SqlDbType.Int),
        //            new SqlParameter("@SortIndex", SqlDbType.Int),
        //            new SqlParameter("@Active", SqlDbType.Int),
        //            new SqlParameter("@Created", SqlDbType.DateTime),
        //            new SqlParameter("@Modified", SqlDbType.DateTime)};
        //    arrParam[0].Value = Image;
        //    arrParam[1].Value = Url;
        //    arrParam[2].Value = Description;
        //    arrParam[3].Value = Target;
        //    arrParam[4].Value = Location;
        //    arrParam[5].Value = SortIndex;
        //    arrParam[6].Value = Active;
        //    arrParam[7].Value = Created;
        //    arrParam[8].Value = Modified;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public void Advert_UpDateItem(int ID, string Image, string Url, string Description, int Target, int Location, int SortIndex, int Active, DateTime Modified)
        //{
        //    string Query = string.Empty;
        //    if (!string.IsNullOrEmpty(Image))
        //    {
        //        Query = "Update tbl_Advert " +
        //                "Set " +
        //                "	Image=@Image, " +
        //                "	Url=@Url, " +
        //                "	Description=@Description, " +
        //                "	Target=@Target, " +
        //                "	Location=@Location, " +
        //                "	SortIndex=@SortIndex, " +
        //                "	Active=@Active, " +
        //                "	Modified=@Modified " +
        //                "Where ID=@ID";
        //    }
        //    else
        //    {
        //        Query = "Update tbl_Advert " +
        //               "Set " +                     
        //               "	Url=@Url, " +
        //               "	Description=@Description, " +
        //               "	Target=@Target, " +
        //               "	Location=@Location, " +
        //               "	SortIndex=@SortIndex, " +
        //               "	Active=@Active, " +
        //               "	Modified=@Modified " +
        //               "Where ID=@ID";
        //    }
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ID", SqlDbType.Int),                 
        //            new SqlParameter("@Image", SqlDbType.NVarChar),
        //            new SqlParameter("@Url", SqlDbType.NVarChar),
        //            new SqlParameter("@Description", SqlDbType.NVarChar),
        //            new SqlParameter("@Target", SqlDbType.Int),
        //            new SqlParameter("@Location", SqlDbType.Int),
        //            new SqlParameter("@SortIndex", SqlDbType.Int),
        //            new SqlParameter("@Active", SqlDbType.Int),
        //            new SqlParameter("@Modified", SqlDbType.DateTime)};
        //    arrParam[0].Value = ID;
        //    arrParam[1].Value = Image;
        //    arrParam[2].Value = Url;
        //    arrParam[3].Value = Description;
        //    arrParam[4].Value = Target;
        //    arrParam[5].Value = Location;
        //    arrParam[6].Value = SortIndex;
        //    arrParam[7].Value = Active;
        //    arrParam[8].Value = Modified;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public DataTable ViewItemAdvertByItemID(int ItemID)
        //{
        //    string Query = "Select ID, Image, Url, Description, Target, Location, SortIndex, Active, Created, Modified, Active,  " +
        //                "Case Active " +
        //                "When 1 Then N'Có' " +
        //                "When 0 Then N'Không'  " +
        //                "End as _Active From tbl_Advert " +
        //                "	Where ID=@ItemID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        public DataTable Adverts_SlideImageReading()
        {
            string Query = "Select Image, Url, Description, Target From tbl_Advert" +
                        " Where Active=1 and Location=1" +
                        " Order By SortIndex, Created desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Adverts_SlideBottomReading()
        {
            string Query = "Select Top 1 Image, Url, Description, Target From tbl_Advert" +
                        " Where Active=1 and Location=2" +
                        " Order By SortIndex, Created desc";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }

        public DataTable Adverts_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "Order By Modified desc ";
            string Query = "Select ID, Image, Url, Description, Target,  " +
                        "Case Target " +
                        "When 0 Then '_self' " +
                        "When 1 Then '_blank' " +
                        "End as _Target, Location, Case Location When 1 Then 'Top' When 2 Then 'Bottom' End as _Location, " +
                        "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active, Created, Modified From tbl_Advert " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Adverts_Search(string Keyword)
        {
            string Query = "Select ID, Image, Url, Description, Target,  " +
                        "Case Target " +
                        "When 0 Then '_self' " +
                        "When 1 Then '_blank' " +
                        "End as _Target, Location, Case Location When 1 Then 'Top' When 2 Then 'Bottom' End as _Location, " +
                        "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active, Created, Modified From tbl_Advert " +
                        "Where Image like N'%'+@Keyword+'%' or Description like N'%'+@Keyword+'%' " +
                        "Order By Modified desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Adverts_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_Advert" +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Adverts_GetImageName(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select Image From tbl_Advert" +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public void Adverts_InsertItem(string Image, string Url, string Description, int Target, int Location, int SortIndex, int Active, DateTime Created, DateTime Modified)
        {
            string Query = "Insert Into tbl_Advert( " +
                        "Image,Url,Description,Target,Location,SortIndex,Active,Created,Modified) " +
                        "Values(@Image,@Url,@Description,@Target,@Location,@SortIndex,@Active,@Created,@Modified) ";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Target", SqlDbType.Int),
                    new SqlParameter("@Location", SqlDbType.Int),
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime)};
            arrParam[0].Value = Image;
            arrParam[1].Value = Url;
            arrParam[2].Value = Description;
            arrParam[3].Value = Target;
            arrParam[4].Value = Location;
            arrParam[5].Value = SortIndex;
            arrParam[6].Value = Active;
            arrParam[7].Value = Created;
            arrParam[8].Value = Modified;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Adverts_UpDateItem(int ID, string Image, string Url, string Description, int Target, int Location, int SortIndex, int Active, DateTime Modified)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(Image))
            {
                Query = "Update tbl_Advert " +
                        "Set " +
                        "	Image=@Image, " +
                        "	Url=@Url, " +
                        "	Description=@Description, " +
                        "	Target=@Target, " +
                        "	Location=@Location, " +
                        "	SortIndex=@SortIndex, " +
                        "	Active=@Active, " +
                        "	Modified=@Modified " +
                        "Where ID=@ID";
            }
            else
            {
                Query = "Update tbl_Advert " +
                       "Set " +
                       "	Url=@Url, " +
                       "	Description=@Description, " +
                       "	Target=@Target, " +
                       "	Location=@Location, " +
                       "	SortIndex=@SortIndex, " +
                       "	Active=@Active, " +
                       "	Modified=@Modified " +
                       "Where ID=@ID";
            }
            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.Int),                 
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@Target", SqlDbType.Int),
                    new SqlParameter("@Location", SqlDbType.Int),
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int),
                    new SqlParameter("@Modified", SqlDbType.DateTime)};
            arrParam[0].Value = ID;
            arrParam[1].Value = Image;
            arrParam[2].Value = Url;
            arrParam[3].Value = Description;
            arrParam[4].Value = Target;
            arrParam[5].Value = Location;
            arrParam[6].Value = SortIndex;
            arrParam[7].Value = Active;
            arrParam[8].Value = Modified;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable Adverts_ViewItemByItemID(int ItemID)
        {
            string Query = "Select ID, Image, Url, Description, Target, Location, SortIndex, Active, Created, Modified, Active,  " +
                        "Case Active " +
                        "When 1 Then N'Có' " +
                        "When 0 Then N'Không'  " +
                        "End as _Active From tbl_Advert " +
                        "	Where ID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        #endregion

        #region TableSupportOnline - GetData
        public DataTable SupportOnline_Reading()
        {
            string Query = "Select FullName, Description, Email, PhoneNumber, Yahoo From tbl_SupportOnline" +
                        " Where Active=1" +
                        " Order By SortIndex";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable SupportOnline_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = " Order By FullName, SortIndex ";
            string Query = "Select SupportID, Description, FullName, Address, Email,  " +
                        "	   PhoneNumber, Yahoo, SortIndex, Active, " +
                        "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_SupportOnline " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void SupportOnline_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_SupportOnline" +
                        " Where SupportID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string SupportOnline_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select FullName From tbl_SupportOnline" +
                        " Where SupportID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public void SupportOnline_InsertItem(string Description, string FullName, string Address, string Email, string PhoneNumber, string Yahoo, int SortIndex, int Active)
        {
            string Query = "Insert Into tbl_SupportOnline( " +
                        "Description,FullName,Address,Email,PhoneNumber,Yahoo,SortIndex,Active) " +
                        "Values(@Description,@FullName,@Address,@Email,@PhoneNumber,@Yahoo,@SortIndex,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@PhoneNumber", SqlDbType.VarChar),
                    new SqlParameter("@Yahoo", SqlDbType.NVarChar),
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = Description;
            arrParam[1].Value = FullName;
            arrParam[2].Value = Address;
            arrParam[3].Value = Email;
            arrParam[4].Value = PhoneNumber;
            arrParam[5].Value = Yahoo;
            arrParam[6].Value = SortIndex;
            arrParam[7].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void SupportOnline_UpDateItem(int SuportID, string Description, string FullName, string Address, string Email, string PhoneNumber, string Yahoo, int SortIndex, int Active)
        {
            string Query = "Update tbl_SupportOnline " +
                        "Set " +
                        "	Description=@Description, " +
                        "	FullName=@FullName, " +
                        "	Address=@Address, " +
                        "	Email=@Email, " +
                        "	PhoneNumber=@PhoneNumber, " +
                        "	Yahoo=@Yahoo,	 " +
                        "	SortIndex=@SortIndex, " +
                        "	Active=@Active " +
                        "Where SupportID=@SupportID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@SupportID", SqlDbType.Int),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@PhoneNumber", SqlDbType.VarChar),
                    new SqlParameter("@Yahoo", SqlDbType.NVarChar),                                  
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = SuportID;
            arrParam[1].Value = Description;
            arrParam[2].Value = FullName;
            arrParam[3].Value = Address;
            arrParam[4].Value = Email;
            arrParam[5].Value = PhoneNumber;
            arrParam[6].Value = Yahoo;
            arrParam[7].Value = SortIndex;
            arrParam[8].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable SupportOnline_ViewItemByID(int ItemID)
        {
            string Query = "Select SupportID, Description, FullName, Address, Email,  " +
                        "	   PhoneNumber, Yahoo, SortIndex, Active, " +
                        "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_SupportOnline " +
                        "	Where SupportID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        #endregion
        //ok
        #region TableBrands - GetData
        //public DataTable BrandsReading()
        //{
        //    string Query = "Select BrandName, Image, Url From tbl_Brands" +
        //                " Where Active=1" +
        //                " Order By SortIndex";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public DataTable GetListBrands()
        //{
        //    string Query = "Select BrandID, BrandName, Image, Url, "+
        //                "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_Brands " +
        //                "Order By SortIndex ";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        //public void DeleteItemFromtblBrands(int ItemID)
        //{
        //    string Query = "Delete From tbl_Brands" +
        //                " Where BrandID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public string tblBrandsGetTitle(int itemid)
        //{
        //    string Value = string.Empty;
        //    string Query = "Select BrandName From tbl_Brands" +
        //                " Where BrandID=@ItemID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = itemid;
        //    Value = DB.ExeCuteScalarParam(Query, arrParam);
        //    return Value;
        //}
        //public DataTable BrandsSearch(string Keyword)
        //{
        //    string Query = "Select BrandID, BrandName, Image, Url, " +
        //                "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_Brands " +
        //                "Where Image like N'%'+@Keyword+'%' or BrandName like N'%'+@Keyword+'%' " +
        //                "Order By SortIndex";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = Keyword;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void Brands_InsertItem(string BrandName, string Image, string Url, int SortIndex, int Active)
        //{
        //    string Query = "Insert Into tbl_Brands( " +
        //                "BrandName,Image,Url,SortIndex,Active) " +
        //                "Values(@BrandName,@Image,@Url,@SortIndex,@Active) ";
        //    SqlParameter[] arrParam ={                  
        //            new SqlParameter("@BrandName", SqlDbType.NVarChar),
        //            new SqlParameter("@Image", SqlDbType.NVarChar),
        //            new SqlParameter("@Url", SqlDbType.NVarChar),                  
        //            new SqlParameter("@SortIndex", SqlDbType.Int),
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = BrandName;
        //    arrParam[1].Value = Image;
        //    arrParam[2].Value = Url;          
        //    arrParam[3].Value = SortIndex;
        //    arrParam[4].Value = Active;          
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        //public DataTable ViewItemBrandsByItemID(int ItemID)
        //{
        //    string Query = "Select BrandID, BrandName, Image, Url, " +
        //                "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_Brands " +
        //                "	Where BrandID=@ItemID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void Brands_UpDateItem(int ItemID, string BrandName, string Image, string Url, int SortIndex, int Active)
        //{
        //    string Query = string.Empty;
        //    if (!string.IsNullOrEmpty(Image))
        //    {
        //        Query = "Update tbl_Brands " +
        //                "Set " +
        //                "	BrandName=@BrandName, " +
        //                "	Image=@Image, " +
        //                "	Url=@Url, " +                       
        //                "	SortIndex=@SortIndex, " +
        //                "	Active=@Active " +                    
        //                "Where BrandID=@ItemID";
        //    }
        //    else
        //    {
        //        Query = "Update tbl_Brands " +
        //               "Set " +
        //               "	BrandName=@BrandName, " +
        //               "	Url=@Url, " +                   
        //               "	SortIndex=@SortIndex, " +
        //               "	Active=@Active " +
        //               "Where BrandID=@ItemID";
        //    }
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int),         
        //            new SqlParameter("@BrandName", SqlDbType.NVarChar),                
        //            new SqlParameter("@Image", SqlDbType.NVarChar),
        //            new SqlParameter("@Url", SqlDbType.NVarChar),               
        //            new SqlParameter("@SortIndex", SqlDbType.Int),
        //            new SqlParameter("@Active", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    arrParam[1].Value = BrandName;
        //    arrParam[2].Value = Image;
        //    arrParam[3].Value = Url;           
        //    arrParam[4].Value = SortIndex;
        //    arrParam[5].Value = Active;         
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        public DataTable Brands_Reading()
        {
            string Query = "Select BrandName, Image, Url From tbl_Brands" +
                        " Where Active=1" +
                        " Order By SortIndex";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable Brands_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "Order By SortIndex ";
            string Query = "Select BrandID, BrandName, Image, Url, " +
                        "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_Brands " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void Brands_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_Brands" +
                        " Where BrandID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Brands_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select BrandName From tbl_Brands" +
                        " Where BrandID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Brands_Search(string Keyword)
        {
            string Query = "Select BrandID, BrandName, Image, Url, " +
                        "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_Brands " +
                        "Where Image like N'%'+@Keyword+'%' or BrandName like N'%'+@Keyword+'%' " +
                        "Order By SortIndex";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Brands_InsertItem(string BrandName, string Image, string Url, int SortIndex, int Active)
        {
            string Query = "Insert Into tbl_Brands( " +
                        "BrandName,Image,Url,SortIndex,Active) " +
                        "Values(@BrandName,@Image,@Url,@SortIndex,@Active) ";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@BrandName", SqlDbType.NVarChar),
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),                  
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = BrandName;
            arrParam[1].Value = Image;
            arrParam[2].Value = Url;
            arrParam[3].Value = SortIndex;
            arrParam[4].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable Brands_ViewItemByItemID(int ItemID)
        {
            string Query = "Select BrandID, BrandName, Image, Url, " +
                        "SortIndex, Active, Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_Brands " +
                        "	Where BrandID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Brands_UpDateItem(int ItemID, string BrandName, string Image, string Url, int SortIndex, int Active)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(Image))
            {
                Query = "Update tbl_Brands " +
                        "Set " +
                        "	BrandName=@BrandName, " +
                        "	Image=@Image, " +
                        "	Url=@Url, " +
                        "	SortIndex=@SortIndex, " +
                        "	Active=@Active " +
                        "Where BrandID=@ItemID";
            }
            else
            {
                Query = "Update tbl_Brands " +
                       "Set " +
                       "	BrandName=@BrandName, " +
                       "	Url=@Url, " +
                       "	SortIndex=@SortIndex, " +
                       "	Active=@Active " +
                       "Where BrandID=@ItemID";
            }
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int),         
                    new SqlParameter("@BrandName", SqlDbType.NVarChar),                
                    new SqlParameter("@Image", SqlDbType.NVarChar),
                    new SqlParameter("@Url", SqlDbType.NVarChar),               
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            arrParam[1].Value = BrandName;
            arrParam[2].Value = Image;
            arrParam[3].Value = Url;
            arrParam[4].Value = SortIndex;
            arrParam[5].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableStatisNews - GetData
        public string StatisNews_GetItemByTitle(string title)
        {
            string RetValues = string.Empty;
            string Query = "Select Body From tbl_StaticNews" +
                           " Where Active=1 and Title=@Title";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Title", SqlDbType.NVarChar)};
            arrParam[0].Value = title;
            DataTable dtResult = new DataTable();
            RetValues = DB.ExeCuteScalarParam(Query, arrParam);
            return RetValues;
        }
        public DataTable StaticNews_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By Modified desc ";
            string Query = "Select NewsID, Title, Body, Created, Modified,  " +
                        "	   Author, Active, " +
                        "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_StaticNews " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void StaticNews_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_StaticNews" +
                        " Where NewsID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string StaticNews_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_StaticNews" +
                        " Where NewsID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable StaticNews_Search(string Keyword)
        {
            string Query = "Select NewsID, Title, Body, Created, Modified,  " +
                        "	   Author, Active, " +
                        "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_StaticNews " +
                        "Where Title like N'%'+@Keyword+'%' or Body like N'%'+@Keyword+'%' " +
                        "Order By Modified desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void StaticNews_InsertItem(string Title, string Body, DateTime Created, DateTime Modified, string Author, int Active)
        {
            string Query = "Insert Into tbl_StaticNews( " +
                        "Title,Body,Created,Modified,Author,Active) " +
                        "Values(@Title,@Body,@Created,@Modified,@Author,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime),
                    new SqlParameter("@Author", SqlDbType.NVarChar),                  
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = Title;
            arrParam[1].Value = Body;
            arrParam[2].Value = Created;
            arrParam[3].Value = Modified;
            arrParam[4].Value = Author;
            arrParam[5].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable StaticNews_ViewItemByID(int ItemID)
        {
            string Query = "Select NewsID, Title, Body, Created, Modified,  " +
                        "	   Author, Active, " +
                        "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_StaticNews " +
                        "	Where NewsID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void StaticNews_UpDateItem(int ItemID, string Title, string Body, DateTime Modified, string Author, int Active)
        {
            string Query = "Update tbl_StaticNews " +
                        "Set " +
                        "	Title=@Title, " +
                        "	Body=@Body, " +
                        "	Modified=@Modified, " +
                        "	Active=@Active " +
                        "Where NewsID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Modified", SqlDbType.DateTime),
                    new SqlParameter("@Author", SqlDbType.NVarChar),                  
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Body;
            arrParam[3].Value = Modified;
            arrParam[4].Value = Author;
            arrParam[5].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //OK
        #region TableCommentProduct - GetData
        public DataTable CommentProduct_GetList(string ProductID, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By Modified desc, Created desc ";
            string Query = "SELECT ID,ProductID,FullName,Email,Title,Body,Created,Modified,Active, " +
                        "  Case Active When 1 Then N'Hiển thị' When 0 Then N'Không hiển thị' END As _Active, " +
                        "  Case Active When 1 Then 'icon_accept.jpg' When 0 Then 'icon_deny.jpg' END As Image " +
                        " FROM tbl_CommentProduct Where ProductID=@ProductID " +
                        OrderBy;
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar)};
            arrParam[0].Value = ProductID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable CommentProduct_GetList(string ProductID)
        {
            string Query = "SELECT ID,ProductID,FullName,Email,Title,Body,Created,Modified,Active FROM tbl_CommentProduct Where ProductID=@ProductID and Active=1 " +
                        "   Order By Created ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar)};
            arrParam[0].Value = ProductID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void CommentProduct_DeleteItemByID(int ItemID)
        {
            string Query = "Delete From tbl_CommentProduct " +
                        " Where ID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void CommentProduct_DeleteItemByProductID(string ItemID)
        {
            string Query = "Delete From tbl_CommentProduct " +
                        " Where ProductID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string CommentProduct_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select FullName From tbl_CommentProduct " +
                        " Where ID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        //public DataTable CommentProduct_Search(string Keyword)
        //{
        //    string Query = "Select NewsID, Title, Body, Created, Modified,  " +
        //                "	   Author, Active, " +
        //                "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_CommentProduct " +
        //                "Where Title like N'%'+@Keyword+'%' or Body like N'%'+@Keyword+'%' " +
        //                "Order By Modified desc ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = Keyword;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        public void CommentProduct_InsertItem(string ProductID, string FullName, string Email, string Title, string Body, DateTime Created, DateTime Modified, int Active)
        {
            string Query = "INSERT INTO tbl_CommentProduct(ProductID,FullName,Email,Title,Body,Created,Modified,Active) " +
                        "     VALUES(@ProductID,@FullName,@Email,@Title,@Body,@Created,@Modified,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime),                                 
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ProductID;
            arrParam[1].Value = FullName;
            arrParam[2].Value = Email;
            arrParam[3].Value = Title;
            arrParam[4].Value = Body;
            arrParam[5].Value = Created;
            arrParam[6].Value = Modified;
            arrParam[7].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string CommentProduct_InsertItemAjax(string ProductID, string FullName, string Email, string Title, string Body, string Created, string Modified, int Active)
        {
            string RetValue = string.Empty;
            try
            {
                string Query = "INSERT INTO tbl_CommentProduct(ProductID,FullName,Email,Title,Body,Created,Modified,Active) " +
                        "     VALUES(@ProductID,@FullName,@Email,@Title,@Body,@Created,@Modified,@Active) ";
                SqlParameter[] arrParam ={
                    new SqlParameter("@ProductID", SqlDbType.VarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Modified", SqlDbType.DateTime),                                 
                    new SqlParameter("@Active", SqlDbType.Int)};
                arrParam[0].Value = ProductID;
                arrParam[1].Value = FullName;
                arrParam[2].Value = Email;
                arrParam[3].Value = Title;
                arrParam[4].Value = new CommonBLL().FormatHtml(Body);
                arrParam[5].Value = Convert.ToDateTime(Created);
                arrParam[6].Value = Convert.ToDateTime(Modified);
                arrParam[7].Value = Active;
                DB.ExeCuteSqlParam(Query, arrParam);
            }
            catch (Exception ex)
            {
                RetValue = "ERROR:" + ex.Message;
            }
            return RetValue;
        }
        public void CommentProduct_UpdateItemShow(int ItemID)
        {
            string Query = "declare @CheckActive int " +
                        " Select @CheckActive=Active From tbl_CommentProduct Where ID=@ID " +
                        " if @CheckActive=1 " +
                        " Begin " +
                        "	Update tbl_CommentProduct " +
                        "	Set Active=0 " +
                        "	Where ID=@ID " +
                        " End " +
                        " Else " +
                        " Begin " +
                        "	Update tbl_CommentProduct " +
                        "	Set Active=1 " +
                        "	Where ID=@ID " +
                        " End ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable CommentProduct_ViewItemByID(int ItemID)
        {
            string Query = "Select ID, ProductID, FullName, Email, Title, Body, Created, Modified, Active, " +
                        "	   Case Active When 0 Then N'Không' When 1 Then N'Có' End as _Active From tbl_CommentProduct " +
                        "	Where ID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void CommentProduct_UpDateItem(int ItemID, string FullName, string Email, string Title, string Body, DateTime Modified, int Active)
        {
            string Query = "Update tbl_CommentProduct " +
                        "Set " +
                        "	FullName=@FullName, " +
                        "	Email=@Email, " +
                        "	Title=@Title, " +
                        "	Body=@Body, " +
                        "	Modified=@Modified, " +
                        "	Active=@Active " +
                        "Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Modified", SqlDbType.DateTime),                            
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            arrParam[1].Value = FullName;
            arrParam[2].Value = Email;
            arrParam[3].Value = Title;
            arrParam[4].Value = Body;
            arrParam[5].Value = Modified;
            arrParam[6].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //OK
        #region TableCartOrder - GetData
        //public string CartOrder_GetItemByTitle(string title)
        //{
        //    string RetValues = string.Empty;
        //    string Query = "Select Body From tbl_CartOrder" +
        //                   " Where Active=1 and Title=@Title";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@Title", SqlDbType.NVarChar)};
        //    arrParam[0].Value = title;
        //    DataTable dtResult = new DataTable();
        //    RetValues = DB.ExeCuteScalarParam(Query, arrParam);
        //    return RetValues;
        //}
        public DataTable CartOrder_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By Created desc ";
            string Query = //"Select Id, Title, Body, Created, Sender, Email, Phone  From tbl_CartOrder " +
                "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
                "SELECT \n" +
                " o.OrderId, "+
                " SUBSTRING(CONVERT(varchar(36),[OrderID]),1,8)     as ID     " +
                "      ,o.[CustommerID]                   \n" +
                "      ,o.[Created], \n" +                
                "      c.FullName, \n" +
                "   c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName \n" +
                "       \n" +
                "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s \n" +
                "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID and  s.StatusID != '5' \n" +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string CartOrder_DeleteItem(string OrderId)
        {
            string reV = string.Empty;
            try
            {
                string Query =
                     " Delete From tbl_OrderDetail " +
                            " Where OrderID=@OrderId ;" +

                    " Delete From tbl_Order" +
                            " Where OrderId=@OrderId";

                SqlParameter[] arrParam ={
                    new SqlParameter("@OrderId", SqlDbType.VarChar)};

                arrParam[0].Value = OrderId;

                DB.ExeCuteSqlParam(Query, arrParam);
            }
            catch (Exception ex) {
                reV = "ERROR: " + ex.Message;
            }
            return reV;
        }
        public string CartOrder_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_CartOrder" +
                        " Where Id=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        //public DataTable CartOrder_Search(string Keyword, string FromDate, string ToDate)
        //{
        //    string Query =
        //                " Select Id, Title, BoDy, Created, Sender, Email, Phone  " +
        //                " From tbl_CartOrder where 1=1 ";
        //    if (!string.IsNullOrEmpty(Keyword))
        //        Query += " And(Title like N'%'+@Keyword+'%' or Body like N'%'+@Keyword+'%' or Sender like N'%'+@Keyword+'%' Or Email like '%'+@Keyword+'%' Or Phone like '%'+@Keyword+'%') ";
        //    if (!string.IsNullOrEmpty(FromDate))
        //        Query += " And convert(datetime,Created,103) >= convert(datetime,'" + FromDate + "',103) ";
        //    if (!string.IsNullOrEmpty(ToDate))
        //        Query += " And convert(datetime,Created,103) < dateadd(dd,1,convert(datetime,'" + ToDate + "',103)) ";
        //    Query += " Order by Created desc ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@Keyword", SqlDbType.NVarChar)};
        //    arrParam[0].Value = Keyword;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}

        public DataTable CartOrder_Search(string Keyword, string FromDate, string ToDate)
        {
            string Query =
                "      SELECT \n" +
                "      o.OrderId, " +
                "      SUBSTRING(CONVERT(varchar(36),[OrderID]),1,8)     as ID     " +
                "      ,o.[CustommerID]                   \n" +
                "      ,o.[Created], \n" +
                "      c.FullName, \n" +
                "      c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName, \n" +                
                "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s \n" +
                "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID \n";
                        
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And OrderId like N'%'+@Keyword+'%'";
            if (!string.IsNullOrEmpty(FromDate))
                Query += " And convert(datetime,o.Created,103) BETWEEN convert(datetime,'" + FromDate + "',103) ";
            if (!string.IsNullOrEmpty(ToDate))
                Query += " And dateadd(dd,1,convert(datetime,'" + ToDate + "',103) " +
                    " )";            

            Query += " Order by Created desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }

        public DataTable CartOrder_Search(string FromDate, string ToDate)
        {
            string Query =
                "      SELECT \n" +
                "      o.OrderId, " +
                "      SUBSTRING(CONVERT(varchar(36),o.OrderID),1,8)     as ID     " +
                "      ,o.[CustommerID]                   \n" +
                "      ,o.[Created], \n" +
                "      c.FullName, \n" +
                "      c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName, \n" +
                "  SUM(d.TotalMoney)  as Total  " +

                "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s , tbl_OrderDetail d \n" +
                "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID \n" +
                "  and d.OrderID = o.OrderID ";
            
            if (!string.IsNullOrEmpty(FromDate))
                Query += " And convert(datetime,o.Created,103) BETWEEN convert(datetime,'" + FromDate + "',103) ";
            if (!string.IsNullOrEmpty(ToDate))
                Query += " And dateadd(dd,1,convert(datetime,'" + ToDate + "',103) " +
                    " )";

            Query +=
                "      group by " +
                "      o.OrderId " +
                "      ,o.[CustommerID] \n" +
                "      ,o.[Created], \n" +
                "      c.FullName, \n" +
                "      c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName \n";

            Query += " Order by Created desc ";
            
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
      

        public void CartOrder_InsertItem(string Title, string Body, DateTime Created, string Sender, string Email, string Phone)
        {
            string Query = "Insert Into tbl_CartOrder( " +
                        "Title,Body,Created,Sender,Email,Phone) " +
                        "Values(@Title,@Body,@Created,@Sender,@Email,@Phone) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@Sender", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),                  
                    new SqlParameter("@Phone", SqlDbType.VarChar)};
            arrParam[0].Value = Title;
            arrParam[1].Value = Body;
            arrParam[2].Value = Created;
            arrParam[3].Value = Sender;
            arrParam[4].Value = Email;
            arrParam[5].Value = Phone;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable CartOrder_ViewItemByID(string ItemID)
        {
            //string Query = "Select Id, Title, Body, Created, Sender, Email, Phone From tbl_CartOrder " +
            //            "	Where Id=@ItemID ";
            string Query = //"Select Id, Title, Body, Created, Sender, Email, Phone  From tbl_CartOrder " +
             "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
             "SELECT \n" +
             " OrderID ,"+
             " SUBSTRING(CONVERT(varchar(36),[OrderID]),1,8)     as ID     " +
             "      ,o.[CustommerID]                   \n" +
             "      ,o.[Created], \n" +
             "      c.FullName, \n" +
             "   c.Email,    \n" +
             "      c.PhoneNumber, \n" +
             "      c.Address, \n" +
             "      s.StatusName \n" +
             "       \n" +
             "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s \n" +
             "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID \n" +
             "  and OrderID =@ItemID ";        

            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void CartOrder_UpDateItem(int ItemID, string Title, string Body, string Sender, string Email, string Phone)
        {
            string Query = "Update tbl_CartOrder " +
                        "Set " +
                        "	Title=@Title, " +
                        "	Body=@Body, " +
                        "	Sender=@Sender, " +
                        "	Email=@Email, " +
                        "	Phone=@Phone " +
                        "Where Id=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),
                    new SqlParameter("@Sender", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),                  
                    new SqlParameter("@Phone", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Body;
            arrParam[3].Value = Sender;
            arrParam[4].Value = Email;
            arrParam[5].Value = Phone;
            DB.ExeCuteSqlParam(Query, arrParam);
        }

        public void UpdateOrderStatus(string ItemID , int StatusId)
        {
            string Query = "Update tbl_Order " +
                        " Set " +
                        " StatusOrderID =@StatusId " +
                        " Where OrderID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar),
                                     new SqlParameter("@StatusId", SqlDbType.SmallInt)};
            arrParam[0].Value = ItemID;
            arrParam[1].Value = StatusId;       
            DB.ExeCuteSqlParam(Query, arrParam);
        }



        #endregion
        //ok
        #region TableGroupNews - GetData
        public DataTable GroupNews_GetTree(int CateID)
        {
            string Query = "IF @CateID =0  " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Url, tc.Decen, tc.Depth, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_GroupNews tc  " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Url, tc.SortIndex, tc.Active " +
                        "	From tbl_GroupNews tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_GroupNews WHERE CateID=@CateID) + '%' " +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable GroupNews_GetTree(int CateID, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("tc", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "	ORDER By tc.Depth asc  ";
            string Query = "IF @CateID =0  " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Url, tc.Decen, tc.Depth, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_GroupNews tc  " +
                        OrderBy +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Url, tc.SortIndex, tc.Active " +
                        "	From tbl_GroupNews tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_GroupNews WHERE CateID=@CateID) + '%' " +
                        OrderBy +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable GroupNews_GetTreeActive(int CateID)
        {
            string Query = "IF @CateID =0  " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Url, tc.Decen, tc.Depth, tc.SortIndex, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_GroupNews tc  " +
                        "   Where tc.Active=1 " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.CateID, tc.ParentID, tc.Title, tc.Decen, tc.Depth, tc.Url, tc.SortIndex, tc.Active " +
                        "	From tbl_GroupNews tc  " +
                        "	Where tc.Depth LIKE (SELECT Depth FROM tbl_GroupNews WHERE CateID=@CateID) + '%' and tc.Active=1" +
                        "	ORDER By tc.Depth asc  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void GroupNews_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_GroupNews" +
                        " Where CateID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string GroupNews_GetTitle(int ItemID)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_GroupNews" +
                        " Where CateID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable GroupNews_Search(int CateID, string Keyword)
        {
            string Query = " Select CateID, ParentID,  " +
                        "	Case Decen  " +
                        "		When 0 Then Title " +
                        "		When 1 Then ':: '+ Title " +
                        "		When 2 Then ':: :: ' + Title " +
                        "		When 3 Then ':: :: :: ' + Title " +
                        "		When 4 Then ':: :: :: :: ' + Title " +
                        "	End " +
                        "	As _Title, " +
                        "	Title, Decen, Depth, Url, SortIndex, Active, " +
                        "    Case Active " +
                        "		   When 1 Then N'Có' " +
                        "		   When 0 Then N'Không'  " +
                        "	END As _Active " +
                        "	From tbl_GroupNews where 1=1 ";
            if (CateID > 0)
                Query += " And Depth LIKE(Select Depth From tbl_GroupNews " +
                        "		Where tbl_GroupNews.CateID=@CateID)+'%' ";
            if (!string.IsNullOrEmpty(Keyword))
                Query += " And(Title like N'%'+@Keyword+'%' Or Url like N'%'+@Keyword+'%') ";
            Query += " Order by Depth ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),                   
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void GroupNews_InsertItem(int ParentID, string Title, string Url, int SortIndex, int Active)
        {
            string Query = "Insert Into tbl_GroupNews( " +
                        "ParentID,Title,Url,SortIndex,Active) " +
                        "Values(@ParentID,@Title,@Url,@SortIndex,@Active) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),                   
                    new SqlParameter("@Url", SqlDbType.NVarChar),                   
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            arrParam[1].Value = Title;
            arrParam[2].Value = Url;
            arrParam[3].Value = SortIndex;
            arrParam[4].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void GroupNews_UpDateItem(int CateID, int ParentID, string Title, string Url, int SortIndex, int Active)
        {
            string Query = "Update tbl_GroupNews " +
                        "Set " +
                        "	ParentID=@ParentID, " +
                        "	Title=@Title, " +
                        "	Url=@Url, " +
                        "	SortIndex=@SortIndex, " +
                        "	Active=@Active " +
                        "Where CateID=@CateID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@ParentID", SqlDbType.Int),
                    new SqlParameter("@Title", SqlDbType.NVarChar),                    
                    new SqlParameter("@Url", SqlDbType.NVarChar),                            
                    new SqlParameter("@SortIndex", SqlDbType.Int),
                    new SqlParameter("@Active", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            arrParam[1].Value = ParentID;
            arrParam[2].Value = Title;
            arrParam[3].Value = Url;
            arrParam[4].Value = SortIndex;
            arrParam[5].Value = Active;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable GroupNews_ViewItemByCateID(int ItemID)
        {
            string Query = "Select CateID, ParentID, Title, Url, SortIndex, Active, " +
                        "	Case Active When 1 Then N'Có' " +
                        "	When 0 Then N'Không' END As _Active From tbl_GroupNews " +
                        "	Where CateID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string GroupNews_GetParentNameByCateID(int ParentID)
        {
            string Query = "Select Title From tbl_GroupNews " +
                        "	Where CateID=@ParentID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ParentID", SqlDbType.Int)};
            arrParam[0].Value = ParentID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableGroupFilter - GetData
        public DataTable GroupFilters_GetGroupFilterIDByCatIDAndGroupFilterName(int parentCatID, string groupfilterName)
        {

            string Query = "Select g.GroupFilterID From tbl_Category tc JOIN tbl_GroupFilters g ON tc.CateID=g.CateID " +
                            "Where tc.Depth LIKE (SELECT Depth FROM tbl_Category WHERE CateID=@CateID) + '%' and GroupFilterName =@GroupFilterName ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@GroupFilterName", SqlDbType.NVarChar,50)};
            arrParam[0].Value = parentCatID;
            arrParam[1].Value = groupfilterName;

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable GroupFilters_ViewItemByCateID(int ItemID)
        {
            string Query = "Select GroupFilterID, GroupFilterName, SortIndex From tbl_GroupFilters " +
                        "	Where CateID=@ItemID " +
                        "   Order By SortIndex ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable GroupFilters_ViewItemByID(int ItemID)
        {
            string Query = "Select GroupFilterID, GroupFilterName, SortIndex From tbl_GroupFilters " +
                        "	Where GroupFilterID=@ItemID " +
                        "   Order By SortIndex ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable GroupFilters_ViewGroupFilterNameByCateID(int CateID)
        {
            string Query = "Select GroupFilterName From tbl_GroupFilters " +
                        "	Where CateID=@CateID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int)};
            arrParam[0].Value = CateID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string GroupFilters_ViewGroupFilterNameByID(int GroupFilterID)
        {
            string Query = "Select GroupFilterName From tbl_GroupFilters " +
                        "	Where GroupFilterID=@GroupFilterID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupFilterID", SqlDbType.Int)};
            arrParam[0].Value = GroupFilterID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        public void GroupFilters_InsertItem(int CateID, string GroupFilterName, int SortIndex, ref string error)
        {
            DataTable dt = Category_GetTree(CateID);
            string query = string.Empty;
            query += "Insert Into tbl_GroupFilters (CateID,GroupFilterName,SortIndex) ";
            int count = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bool checkGroupFilterName = false;
                DataTable dtGFname = GroupFilters_ViewGroupFilterNameByCateID(int.Parse(dt.Rows[i]["CateID"].ToString()));
                for (int j = 0; j < dtGFname.Rows.Count; j++)
                {
                    if (dtGFname.Rows[j][0].ToString().ToLower().Equals(GroupFilterName.ToLower()))
                    {
                        checkGroupFilterName = true;
                        break;
                    }
                }
                if (!checkGroupFilterName)
                {
                    query +=
                    " SELECT " + dt.Rows[i]["CateID"] + ",@GroupFilterName,@SortIndex";
                    if (i < dt.Rows.Count - 1)
                        query += " UNION ALL ";
                }
                else
                    count++;

            }
            if (count == dt.Rows.Count)
            {
                error = "ERROR";
                return;
            }
            int loc = query.Trim().LastIndexOf("UNION ALL");
            if ((query.Trim().Length - loc) < 10)
                query = query.Remove(loc).ToString();
            SqlParameter[] arrParam ={                
                    new SqlParameter("@GroupFilterName", SqlDbType.NVarChar,50),                         
                    new SqlParameter("@SortIndex", SqlDbType.Int)};
            arrParam[0].Value = GroupFilterName;
            arrParam[1].Value = SortIndex;
            DB.ExeCuteSqlParam(query, arrParam);
            #region Drap
            //DataTable dt = Category_GetTree(CateID);
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    string Query = "Insert Into tbl_GroupFilters( " +
            //           "CateID,GroupFilterName,SortIndex) " +
            //           "Values(@CateID,@GroupFilterName,@SortIndex) ";
            //    SqlParameter[] arrParam ={
            //        new SqlParameter("@CateID", SqlDbType.Int),
            //        new SqlParameter("@GroupFilterName", SqlDbType.NVarChar,50),                         
            //        new SqlParameter("@SortIndex", SqlDbType.Int)};
            //    arrParam[0].Value = int.Parse(dt.Rows[i]["CateID"].ToString());
            //    arrParam[1].Value = GroupFilterName;
            //    arrParam[2].Value = SortIndex;
            //    DB.ExeCuteSqlParam(Query, arrParam);
            //}   
            #endregion
        }
        public void GroupFilters_UpDateItem(int GroupFilterID, int CateID, string GroupFilterName, int SortIndex)
        {
            string Query = "Update tbl_GroupFilters " +
                        "Set " +
                        "	CateID=@CateID, " +
                        "	GroupFilterName=@GroupFilterName, " +
                        "	SortIndex=@SortIndex " +
                        "Where GroupFilterID=@GroupFilterID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupFilterID", SqlDbType.Int),
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@GroupFilterName", SqlDbType.NVarChar),                          
                    new SqlParameter("@SortIndex", SqlDbType.Int)};
            arrParam[0].Value = GroupFilterID;
            arrParam[1].Value = CateID;
            arrParam[2].Value = GroupFilterName;
            arrParam[3].Value = SortIndex;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void GroupFilters_DeleteItem(int ItemID, int CateID)
        {
            string GroupFilterName = GroupFilters_ViewGroupFilterNameByID(ItemID);
            DataTable dtListGroupID = GroupFilters_GetGroupFilterIDByCatIDAndGroupFilterName(CateID, GroupFilterName);
            for (int i = 0; i < dtListGroupID.Rows.Count; i++)
            {
                string Query1 = "Delete From tbl_Filter" +
                        " Where GroupFilterID=@GroupFilterID";
                SqlParameter[] arrParam ={
                    new SqlParameter("@GroupFilterID", SqlDbType.Int)};
                arrParam[0].Value = int.Parse(dtListGroupID.Rows[i]["GroupFilterID"].ToString());
                DB.ExeCuteSqlParam(Query1, arrParam);
            }
            DataTable dtListCat = Category_GetTree(CateID);
            for (int j = 0; j < dtListCat.Rows.Count; j++)
            {
                string Query = "Delete From tbl_GroupFilters" +
                           " Where CateID=@CateID and GroupFilterName=@GroupFilterName ";
                SqlParameter[] arrParam ={
                    new SqlParameter("@CateID", SqlDbType.Int),
                    new SqlParameter("@GroupFilterName", SqlDbType.NVarChar,50)};
                arrParam[0].Value = int.Parse(dtListCat.Rows[j]["CateID"].ToString());
                arrParam[1].Value = GroupFilterName;
                DB.ExeCuteSqlParam(Query, arrParam);
            }
        }
        #endregion
        //ok
        #region TableFilter - GetData
        public DataTable Filter_ViewFilterNameByGroupFilterID(int GroupFilterID)
        {
            string Query = "Select FilterName From tbl_Filter " +
                        "	Where GroupFilterID=@GroupFilterID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupFilterID", SqlDbType.Int)};
            arrParam[0].Value = GroupFilterID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Filter_ViewItemFilterByGroupFilterID(int GroupFilterID)
        {
            string Query = "Select FilterID, GroupFilterID, FilterName, CheckPrice, FromPrice, ToPrice, SortIndex From tbl_Filter " +
                        "	Where GroupFilterID=@GroupFilterID " +
                        "   Order By SortIndex ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupFilterID", SqlDbType.Int)};
            arrParam[0].Value = GroupFilterID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Filter_ViewItemByID(int FilterID)
        {
            string Query = "Select FilterID, GroupFilterID, FilterName, CheckPrice, FromPrice, ToPrice, SortIndex From tbl_Filter " +
                        "	Where FilterID=@FilterID " +
                        "   Order By SortIndex ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@FilterID", SqlDbType.Int)};
            arrParam[0].Value = FilterID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string Filter_GetFilterNameByID(int FilterID)
        {
            string Query = "Select FilterName From tbl_Filter " +
                        "	Where FilterID=@FilterID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@FilterID", SqlDbType.Int)};
            arrParam[0].Value = FilterID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        public string Filter_GetGroupFilterIDByID(int FilterID)
        {
            string Query = "Select GroupFilterID From tbl_Filter " +
                        "	Where FilterID=@FilterID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@FilterID", SqlDbType.Int)};
            arrParam[0].Value = FilterID;
            return DB.ExeCuteScalarParam(Query, arrParam);
        }
        public void Filter_InsertItem(int GroupFilterID, string FilterName, int CheckPrice, float FromPrice, float ToPrice, int SortIndex, int catid, string groupFilterName, ref string error)
        {
            DataTable dtCat = GroupFilters_GetGroupFilterIDByCatIDAndGroupFilterName(catid, groupFilterName);
            string query = string.Empty;
            int count = 0;
            query += "Insert Into tbl_Filter (GroupFilterID,FilterName,CheckPrice, FromPrice,ToPrice, SortIndex) ";
            for (int i = 0; i < dtCat.Rows.Count; i++)
            {
                bool checkFilterName = false;
                DataTable dtFilterName = Filter_ViewFilterNameByGroupFilterID(int.Parse(dtCat.Rows[i][0].ToString()));
                for (int j = 0; j < dtFilterName.Rows.Count; j++)
                {
                    if (dtFilterName.Rows[j][0].ToString().ToLower().Equals(FilterName.ToLower()))
                    {
                        checkFilterName = true;
                        break;
                    }
                }
                if (!checkFilterName)
                {
                    query +=
                     " SELECT " + dtCat.Rows[i][0] + ",@FilterName ,@CheckPrice,@FromPrice,@ToPrice,@SortIndex";
                    if (i < dtCat.Rows.Count - 1)
                        query += " UNION ALL ";
                }
                else
                    count++;

            }
            if (count == dtCat.Rows.Count)
            {
                error = "ERROR";
                return;
            }
            int loc = query.Trim().LastIndexOf("UNION ALL");
            if ((query.Trim().Length - loc) < 10)
                query = query.Remove(loc).ToString();
            SqlParameter[] arrParam ={
                    new SqlParameter("@FilterName", SqlDbType.NVarChar,50),
                    new SqlParameter("@CheckPrice", SqlDbType.Int),   
                    new SqlParameter("@FromPrice", SqlDbType.Float),
                    new SqlParameter("@ToPrice", SqlDbType.Float), 
                    new SqlParameter("@SortIndex", SqlDbType.Int)
                   };
            arrParam[0].Value = FilterName;
            arrParam[1].Value = CheckPrice;
            arrParam[2].Value = FromPrice;
            arrParam[3].Value = ToPrice;
            arrParam[4].Value = SortIndex;
            DB.ExeCuteSqlParam(query.ToString(), arrParam);
            #region Drag
            //string Query = "Insert Into tbl_Filter( " +
            //            "GroupFilterID,FilterName,CheckPrice,FromPrice,ToPrice,SortIndex) " +
            //            "Values(@GroupFilterID,@FilterName,@CheckPrice,@FromPrice,@ToPrice,@SortIndex) ";
            //SqlParameter[] arrParam ={
            //       new SqlParameter("@GroupFilterID", SqlDbType.Int),
            //       new SqlParameter("@FilterName", SqlDbType.NVarChar),   
            //       new SqlParameter("@CheckPrice", SqlDbType.Int),
            //       new SqlParameter("@FromPrice", SqlDbType.Float), 
            //       new SqlParameter("@ToPrice", SqlDbType.Float), 
            //       new SqlParameter("@SortIndex", SqlDbType.Int)};
            //arrParam[0].Value = GroupFilterID;
            //arrParam[1].Value = FilterName;
            //arrParam[2].Value = CheckPrice;
            //arrParam[3].Value = FromPrice;
            //arrParam[4].Value = ToPrice;
            //arrParam[5].Value = SortIndex;
            //DB.ExeCuteSqlParam(Query, arrParam);
            #endregion
        }
        public void Filter_UpDateItem(int FilterID, int GroupFilterID, string FilterName, int CheckPrice, float FromPrice, float ToPrice, int SortIndex)
        {
            string Query = "Update tbl_Filter " +
                        "Set " +
                        "	GroupFilterID=@GroupFilterID, " +
                        "	FilterName=@FilterName, " +
                        "	CheckPrice=@CheckPrice, " +
                        "	FromPrice=@FromPrice, " +
                        "	ToPrice=@ToPrice, " +
                        "	SortIndex=@SortIndex " +
                        "Where FilterID=@FilterID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@FilterID", SqlDbType.Int),
                    new SqlParameter("@GroupFilterID", SqlDbType.Int),
                    new SqlParameter("@FilterName", SqlDbType.NVarChar),                          
                    new SqlParameter("@CheckPrice", SqlDbType.Int),
                    new SqlParameter("@FromPrice", SqlDbType.Float),
                    new SqlParameter("@ToPrice", SqlDbType.Float),                                     
                    new SqlParameter("@SortIndex", SqlDbType.Int)};
            arrParam[0].Value = FilterID;
            arrParam[1].Value = GroupFilterID;
            arrParam[2].Value = FilterName;
            arrParam[3].Value = CheckPrice;
            arrParam[4].Value = FromPrice;
            arrParam[5].Value = ToPrice;
            arrParam[6].Value = SortIndex;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Filter_DeleteItemByFilterID(int ItemID, int CateID, int GroupFilterID)
        {
            string FilterName = Filter_GetFilterNameByID(ItemID);
            DataTable dtGroupFilterID = GroupFilters_GetGroupFilterIDByCatIDAndGroupFilterName(CateID, GroupFilters_ViewGroupFilterNameByID(GroupFilterID));
            for (int i = 0; i < dtGroupFilterID.Rows.Count; i++)
            {
                string Query = "Delete From tbl_Filter " +
                             " Where GroupFilterID=@GroupFilterID and FilterName=@FilterName ";
                SqlParameter[] arrParam ={
                        new SqlParameter("@GroupFilterID", SqlDbType.Int),
                        new SqlParameter("@FilterName", SqlDbType.NVarChar,50)};
                arrParam[0].Value = int.Parse(dtGroupFilterID.Rows[i]["GroupFilterID"].ToString());
                arrParam[1].Value = FilterName;
                DB.ExeCuteSqlParam(Query, arrParam);
            }
        }
        public void Filter_DeleteItemByGroupFilterID(int ItemID)
        {
            string Query = "Delete From tbl_Filter" +
                        " Where GroupFilterID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        #region Shopping Cart
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string RenderPrintShoppingCartClient(string dtproducts)
        {
            string titleVal = new BLL.CmsBLL().StatisNews_GetItemByTitle("print");
            StringBuilder Html = new StringBuilder();
            Html.Append(
              "<div id=\"divcartholder\" class=\"print_contactholder\">\n" +
              "<div class=\"print_header\">\n" + titleVal + "</div>" +
                "	<h1 class=\"printtitle\">Đơn hàng</h1>\n" +
                "	<div class=\"contactform\">\n" + dtproducts +
                //"											\n" +
                //    "		<table id=\"dtcart\" class=\"carttable\">\n" +
                //     "			<tr>\n" +
                //    "				<th class=\"stt\">STT</th>\n" +
                //    "				<th class=\"name\">Tên sản phẩm</th>\n" +
                //    "				<th class=\"price\">Giá tiền (vnđ)</th>\n" +
                //    "				<th class=\"sl\">Số lượng</th>\n" +
                //    "				<th class=\"total\">Thành tiền</th>\n" +
                //    "				<th class=\"function\">Bảo hành</th>\n" +
                //    "			</tr>\n"
                //    );
                //double total = 0;
                //string productUrl = string.Empty;
                //int itemnumber = 0;
                //double price = 0;
                //string productCode = string.Empty;
                //for (int i = 0; i < dtproducts.Rows.Count; i++)
                //{
                //    productCode = dtproducts.Rows[i]["ProductID"].ToString();
                //    itemnumber = Convert.ToInt16(dtproducts.Rows[i]["ItemNumber"]);
                //    price = Convert.ToDouble(dtproducts.Rows[i]["NewPrice"]);
                //    Html.Append(
                //    "			<tr >\n" +
                //    "				<td class=\"print_stt\">" + (i + 1) + "</td>\n" +
                //    "				<td class=\"print_name\">" + dtproducts.Rows[i]["ProductName"] + "</td>\n" +
                //    "				<td class=\"print_price\">" + price.ToString("#,###") + "</td>\n" +
                //    "				<td class=\"print_sl\">" + itemnumber + " </td>\n" +
                //    "				<td class=\"print_total\">" + (price * itemnumber).ToString("#,###") + "</td>\n" +
                //    "				<td class=\"print_total\">" + dtproducts.Rows[i]["BaoHanh"] + "</td>\n" +
                //    "			</tr>\n");
                //    total += (price * itemnumber);
                //}
                //Html.Append(
                //    "			<tr>\n" +
                //    "				<td class=\"totalsum\" colspan=\"6\">\n" +
                //    "					\n" +
                //    "					Tổng giá tiền: " + total.ToString("#,###") + " vnđ <br />\n" +
                //    "					\n" +
                //    //"					<input class=\"buttonupdate\" type=\"button\" value=\"Cập nhật\" onclick=\"javascript:OnclientUpdateCart();\" />\n" +
                //    //"					<input class=\"buttonprint\" type=\"button\" value=\"In đơn hàng\" onclick=\"javascript:OnclientPrintCart('" + DAL.EnvInfo.HttpRoot + "');\" />\n" +
                //    //"					<input class=\"buttoncheckout\" type=\"button\" value=\"Đặt hàng\"onclick=\"javascript:OnclientSubmitCart();\" />\n" +
                //    "				</td>\n" +
                //    "			</tr>\n" +
                //    "		</table>\n" +

                "	</div>\n" +
                "	<div class=\"print_footer\">\n" +
                "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n" +
                "  <tbody><tr>\n" +
                "    <td width=\"687\" valign=\"top\"><p>Ghi chú   			&nbsp; <br>\n" +
                "      - Thuế VAT: Giá trên đã   			bao gồm thuế VAT  			&nbsp; <br>\n" +
                "      - Bảo hành:.........................................<br>\n" +
                "      - Lắp đặt và vận chuyển:.......................&nbsp; <br>\n" +
                "    - Thanh toán:.......................................&nbsp;    </p>\n" +
                "    </td>\n" +
                "    <td width=\"416\" valign=\"top\" height=\"115\" align=\"center\" rowspan=\"5\"><p>Khách hàng ký <br>\n" +
                "  (<em>Ghi rõ họ tên và đóng dấu nếu có</em>)</p>\n" +
                "    </td>\n" +
                "  </tr>\n" +
                "</tbody></table>\n" +
                "<table>\n" +
                    "<tr>\n" +
                    "    <td width=\"80%\" align=\"right\">&nbsp;<a onclick=\"window.print()\" href=\"#\"><img border=\"0\" width=\"40\" height=\"40\" src=\"" + DAL.EnvInfo.HttpRoot + "images/icons/print.png\"> In trang này</a>&nbsp;&nbsp;</td>\n" +
                    "    <td width=\"20%\">&nbsp;<a onclick=\"window.close()\" href=\"#\"><img border=\"0\" width=\"40\" height=\"40\" src=\"" + DAL.EnvInfo.HttpRoot + "images/icons/print_close.png\">  Đóng lại</a></td>\n" +
                    "</tr>\n" +
                "</table>\n" +
                "</div>\n" +
                "</div>\n"

                );

            return Html.ToString();
        }

        public string RenderPrintShoppingCart(DataTable dtproducts)
        {
            string titleVal = string.Empty;
            try
            {
                titleVal = new BLL.CmsBLL().StatisNews_GetItemByTitle("PrintHeader");
            }
            catch { }
            StringBuilder Html = new StringBuilder();
            Html.Append(
              "<div id=\"divcartholder\" class=\"print_contactholder\">\n" +
              "<div class=\"print_header\">\n" + titleVal + "</div>" +
                "	<h1 class=\"printtitle\">" + MyResource.Order + "</h1>\n" +
                "	<div class=\"contactform\">\n" +
                "											\n" +
                "		<table id=\"dtcart\" class=\"carttable\">\n" +
                 "			<tr>\n" +
                "				<th class=\"stt\">STT</th>\n" +
                "				<th class=\"name\">" + MyResource.ProductName + "</th>\n" +
                "				<th class=\"price\">" + MyResource.ProductPrice + " (vnđ)</th>\n" +
                "				<th class=\"sl\">" + MyResource.Quantities + "</th>\n" +
                "				<th class=\"total\">" + MyResource.Amount + "</th>\n" +
                "			</tr>\n"
                );
            double total = 0;
            string productUrl = string.Empty;
            int itemnumber = 0;
            double price = 0;
            string productCode = string.Empty;
            for (int i = 0; i < dtproducts.Rows.Count; i++)
            {
                productCode = dtproducts.Rows[i]["ProductID"].ToString();
                itemnumber = Convert.ToInt16(dtproducts.Rows[i]["ItemNumber"]);
                price = Convert.ToDouble(dtproducts.Rows[i]["NewPrice"]);
                Html.Append(
                "			<tr >\n" +
                "				<td class=\"print_stt\">" + (i + 1) + "</td>\n" +
                "				<td class=\"print_name\">" + dtproducts.Rows[i]["ProductName"] + "</td>\n" +
                "				<td class=\"print_price\">" + price.ToString("#,###") + "</td>\n" +
                "				<td class=\"print_sl\">" + itemnumber + " </td>\n" +
                "				<td class=\"print_total\">" + (price * itemnumber).ToString("#,###") + "</td>\n" +
                "			</tr>\n");
                total += (price * itemnumber);
            }
            Html.Append(
                "			<tr>\n" +
                "				<td class=\"totalsum\" colspan=\"6\">\n" +
                "					\n" +
                "					" + MyResource.GrandTotal + ": " + total.ToString("#,###") + " vnđ <br />\n" +
                "					\n" +
                "				</td>\n" +
                "			</tr>\n" +
                "		</table>\n" +

                "	</div>\n" +
                "	<div class=\"print_footer\">\n" +
                "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n" +
                "  <tbody><tr>\n" +
                "    <td width=\"687\" valign=\"top\"><p>" + MyResource.Note + "   			&nbsp; <br>\n" +
                "      - " + MyResource.VAT + "  			&nbsp; <br>\n" +
                "    - " + MyResource.Amount + ":.......................................&nbsp;    </p>\n" +
                "    </td>\n" +
                "    <td width=\"416\" valign=\"top\" height=\"115\" align=\"center\" rowspan=\"5\"><p>" + MyResource.Signatures + "<br>\n" +
                "  (<em>" + MyResource.ClosingSign + "</em>)</p>\n" +
                "    </td>\n" +
                "  </tr>\n" +
                "</tbody></table>\n" +
                "<table>\n" +
                    "<tr>\n" +
                    "    <td width=\"80%\" align=\"right\">&nbsp;<a onclick=\"window.print()\" href=\"#\"><img border=\"0\" width=\"40\" height=\"40\" src=\"" + DAL.EnvInfo.HttpRoot + "images/icons/print.png\"> " + MyResource.Print + "</a>&nbsp;&nbsp;</td>\n" +
                    "    <td width=\"20%\">&nbsp;<a onclick=\"window.close()\" href=\"#\"><img border=\"0\" width=\"40\" height=\"40\" src=\"" + DAL.EnvInfo.HttpRoot + "images/icons/print_close.png\">  " + MyResource.Close + "</a></td>\n" +
                    "</tr>\n" +
                "</table>\n" +
                "</div>\n" +
                "</div>\n"

                );

            return Html.ToString();
        }
        public string RenderShoppingCartDetail(string siteid, DataTable dtproducts, bool isLogin, string loginName)
        {            
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divcartholder\" class=\"contactholder\">\n" +
                "	<h1 class=\"title\">" + MyResource.MyCart + "</h1>\n" +
                "	<span class=\"legend\">\n" +
                "	</span>\n" +
                "	<div class=\"contactform\">\n" +
                "											\n" +
                "		<table id=\"dtcart\" class=\"carttable\">\n" +
                 "			<tr>\n" +
                "				<th class=\"stt\">" + MyResource.Index + "</th>\n" +
                "				<th class=\"name\">" + MyResource.ProductName + "</th>\n" +
                "				<th class=\"price\">" + MyResource.ProductPrice + " (vnđ)</th>\n" +
                "				<th class=\"sl\">" + MyResource.Quantities + "</th>\n" +
                "				<th class=\"total\">" + MyResource.Amount + "</th>\n" +
                "				<th class=\"function\">&nbsp;</th>\n" +
                "			</tr>\n"
                );
            double total = 0;
            string productUrl = string.Empty;
            int itemnumber = 0;
            double price = 0;
            string productCode = string.Empty;
            for (int i = 0; i < dtproducts.Rows.Count; i++)
            {
                productCode = dtproducts.Rows[i]["ProductID"].ToString();
                productUrl = Screen.BuildUrlForProductDetails(productCode, dtproducts.Rows[i]["ProductName"].ToString(),
                                  dtproducts.Rows[i]["CateID"].ToString(), siteid);
                itemnumber = Convert.ToInt16(dtproducts.Rows[i]["ItemNumber"]);
                price = Convert.ToDouble(dtproducts.Rows[i]["NewPrice"]);
                Html.Append(                    

                "			<tr class=\"odd\">\n" +
                "				<td class=\"stt\">" + (i + 1) + "</td>\n" +
                "				<td class=\"name\"><a href=\"" + productUrl + "\">" + dtproducts.Rows[i]["ProductName"] + "</a></td>\n" +
                "				<td class=\"price\">" + price.ToString("#,###") + "</td>\n" +
                "				<td class=\"sl\"><input id=\"txt_" + productCode + "\" type=\"text\" value=\"" + itemnumber + "\" class=\"slinput\" /></td>\n" +
                "				<td class=\"total\">" + (price * itemnumber).ToString("#,###") + "</td>\n" +
                "				<td class=\"function\">\n" +
                "					<a href=\"javascript:RemoveCartItem('" + productCode + "');\">" + MyResource.Delete + "</a>\n" +
                "				</td>\n" +
                "			</tr>\n");
                total += (price * itemnumber);
            }
            Html.Append(
                "			<tr>\n" +
                "				<td class=\"totalsum\" colspan=\"6\">\n" +
                "					\n" +
                "					" + MyResource.GrandTotal + ": " + total.ToString("#,###") + " vnđ <br />\n" +
                "					\n" +                
                "				</td>\n" +
                "			</tr>\n" +
                "		</table>\n" +
                "<table class=\"carttable\">" +
                "<tr>"+
                "				<td class=\"totalsum\" colspan=\"6\">\n" +                
                "					<input class=\"buttonupdate\" type=\"button\" value=\"" + MyResource.Update + "\" onclick=\"javascript:OnclientUpdateCart();\" />\n" +
                "					<input class=\"buttonprint\" type=\"button\" value=\"" + MyResource.Print + "\" onclick=\"javascript:OnclientPrintCart('" + DAL.EnvInfo.HttpRoot + "');\" />\n" +
                "					<input class=\"buttoncheckout\" type=\"button\" value=\"" + MyResource.Submit + "\"onclick=\"javascript:OnclientSubmitCart('" + DAL.EnvInfo.HttpRoot + "','" + isLogin + "','" + loginName + "');\" />\n" +
                "				</td>\n" +
                "</tr>" +
                "</table>"+
                "	</div>\n" +
                "</div>\n"
                );

            if (dtproducts != null)
            {
                dtCart = new DataTable();
                dtCart = dtproducts;
            }

            return Html.ToString();
        }
        #endregion
        //ok
        #region TabelModules - GetData
        public DataTable Modules_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By SortIndex, ModuleID ";
            string Query = "Select ModuleID, ModuleName, SortIndex From tbl_Modules " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void Modules_DeleteItem(string ItemID)
        {
            string Query = "Delete From tbl_Modules" +
                        " Where ModuleID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Modules_GetTitle(string itemid)
        {
            string Value = string.Empty;
            string Query = "Select ModuleName From tbl_Modules" +
                        " Where ModuleID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Modules_Search(string Keyword)
        {
            string Query = "Select ModuleID, ModuleName, SortIndex From tbl_Modules " +
                        "Where ModuleName like N'%'+@Keyword+'%' or ModuleID like N'%'+@Keyword+'%' " +
                        "Order By SortIndex, ModuleID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Modules_InsertItem(string ModuleID, string ModuleName, int SortIndex)
        {
            string Query = "Insert Into tbl_Modules( " +
                        "ModuleID,ModuleName,SortIndex) " +
                        "Values(@ModuleID,@ModuleName,@SortIndex) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ModuleID", SqlDbType.VarChar),
                    new SqlParameter("@ModuleName", SqlDbType.NVarChar),                               
                    new SqlParameter("@SortIndex", SqlDbType.Int)};
            arrParam[0].Value = ModuleID;
            arrParam[1].Value = ModuleName;
            arrParam[2].Value = SortIndex;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Modules_CheckPermissFuncID(string ModuleID)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_Modules " +
                           "Where LOWER(ModuleID)=LOWER(@ModuleID) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ModuleID", SqlDbType.VarChar)};
            arrParam[0].Value = ModuleID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Modules_ViewItemByID(string ItemID)
        {
            string Query = "Select ModuleID, ModuleName, SortIndex From tbl_Modules " +
                        "	Where ModuleID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Modules_UpDateItem(string ModuleID, string ModuleName, int SortIndex)
        {
            string Query = "Update tbl_Modules " +
                        "Set " +
                        "	ModuleName=@ModuleName, " +
                        "	SortIndex=@SortIndex " +
                        "Where ModuleID=@ModuleID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ModuleID", SqlDbType.VarChar),
                    new SqlParameter("@ModuleName", SqlDbType.NVarChar),                               
                    new SqlParameter("@SortIndex", SqlDbType.Int)};
            arrParam[0].Value = ModuleID;
            arrParam[1].Value = ModuleName;
            arrParam[2].Value = SortIndex;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableGroupModule - GetData
        public DataTable GroupModule_Search(Guid GroupID)
        {
            string Query = "	Select m.ModuleID, m.ModuleName, m.SortIndex, gm.GroupID, gm.PermissionNumber " +
                        "	  From tbl_Modules m JOIN tbl_GroupModule gm ON m.ModuleID=gm.ModuleID" +
                        "	Where gm.GroupID=@GroupID " +
                        "	Order By m.SortIndex, m.ModuleName  ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = GroupID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable GroupModule_GetListPermissionNumberByUserNameAndModuleID(string ModuleID, string UserName)
        {
            string Query = "select PermissionNumber from tbl_GroupModule gm JOIN tbl_Groups g ON gm.GroupID = g.GroupID  " +
                        "where gm.ModuleID=@ModuleID and gm.GroupID IN  " +
                        "(select g.GroupID from tbl_Manager m JOIN tbl_GroupUser g ON m.UserName = g.UserName where m.UserName=@UserName) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ModuleID", SqlDbType.VarChar),
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = ModuleID;
            arrParam[1].Value = UserName;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void GroupModule_InsertItem(Guid GroupID, string ModuleID)
        {
            string Query = " Insert Into tbl_GroupModule( " +
                        " GroupID,ModuleID) " +
                        " Values(@GroupID,@ModuleID) ";

            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@ModuleID", SqlDbType.VarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = ModuleID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string GroupModule_CheckValueToInsert(Guid GroupID, string ModuleID)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_GroupModule gm " +
                           "Where gm.ModuleID=@ModuleID and gm.GroupID=@GroupID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@ModuleID", SqlDbType.VarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = ModuleID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public void GroupModule_DeleteItem(Guid GroupID, string ModuleID)
        {
            string Query = "Delete From tbl_GroupModule " +
                        " Where ModuleID=@ModuleID and GroupID=@GroupID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@ModuleID", SqlDbType.VarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = ModuleID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void GroupModule_UpDateItem(Guid GroupID, string ModuleID, int PermissionNumber)
        {
            string Query = "Update tbl_GroupModule " +
                        "Set " +
                        "	PermissionNumber=@PermissionNumber " +
                        "Where GroupID=@GroupID and ModuleID=@ModuleID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@ModuleID", SqlDbType.VarChar),                               
                    new SqlParameter("@PermissionNumber", SqlDbType.Int)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = ModuleID;
            arrParam[2].Value = PermissionNumber;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableLeftMenuGroup - GetData
        public DataTable LeftMenuGroup_Search(Guid GroupID, int MenuID)
        {
            string Query = "IF @MenuID =0  " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_LeftMenu tc JOIN tbl_LeftMenuGroup lmg ON tc.MenuID=lmg.MenuID " +
                        "	Where lmg.GroupID=@GroupID " +
                        "	Order By tc.Depth  " +
                        "End " +
                        "	-- Ngược lại Get Sub Tree " +
                        "ELSE " +
                        "BEGIN " +
                        "	Select tc.MenuID, tc.ParentID,  " +
                        "	Case tc.Decen  " +
                        "		When 0 Then tc.Title " +
                        "		When 1 Then ':: '+ tc.Title " +
                        "		When 2 Then ':: :: ' + tc.Title " +
                        "		When 3 Then ':: :: :: ' + tc.Title " +
                        "		When 4 Then ':: :: :: :: ' + tc.Title " +
                        "	End " +
                        "	As _Title, " +
                        "	tc.Title, tc.Decen, tc.Depth, " +
                        "		   tc.Url, tc.Active, " +
                        "		   Case Active When 1 Then N'Có' " +
                        "		When 0 Then N'Không' END As _Active " +
                        "	  From tbl_LeftMenu tc JOIN tbl_LeftMenuGroup lmg ON tc.MenuID=lmg.MenuID " +
                        "	Order By tc.Depth  " +
                        "END ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = MenuID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void LeftMenuGroup_InsertItem(Guid GroupID, int MenuID)
        {
            string Query = " Insert Into tbl_LeftMenuGroup( " +
                        " GroupID,MenuID) " +
                        " Values(@GroupID,@MenuID) ";

            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = MenuID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string LeftMenuGroup_CheckValueToInsert(Guid GroupID, int MenuID)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_LeftMenuGroup lmg " +
                           "Where lmg.MenuID=@MenuID and lmg.GroupID=@GroupID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = MenuID;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public void LeftMenuGroup_DeleteItem(Guid GroupID, int MenuID)
        {
            string Query = "Delete From tbl_LeftMenuGroup " +
                        " Where MenuID=@MenuID and GroupID=@GroupID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@MenuID", SqlDbType.Int)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = MenuID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region MenuPermission
        public static DataTable GetInfoModule(string Key)
        {
            DataTable dt = new DataTable();
            string xmlFile = HttpContext.Current.Server.MapPath("" + DAL.EnvInfo.PathConfigPermiss + "MenuConfig.xml");
            System.IO.FileInfo fi = new System.IO.FileInfo(xmlFile);
            if (fi.Exists)
            {
                DataSet ds = new DataSet("Info");
                ds.ReadXml(xmlFile);
                DataView dv = new DataView(ds.Tables[0], "Key='" + Key + "'", "Key ASC", DataViewRowState.CurrentRows);
                if (dv.Count != 0)
                {
                    //return (string)dv[0]["Value"];
                    dt = dv.ToTable();
                }
            }
            return dt;
        }
        public bool HasPermissionDelete(string Key)
        {
            bool RetValue = false;
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
                if (dt.Rows[0]["IsDelete"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.DeleteItem))
                        RetValue = true;
            return RetValue;
        }
        public bool HasPermissionEdit(string Key)
        {
            bool RetValue = false;
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
                if (dt.Rows[0]["IsEdit"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.EditItem))
                        RetValue = true;
            return RetValue;
        }
        public bool HasPermissionView(string Key)
        {
            bool RetValue = false;
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
                if (dt.Rows[0]["IsEdit"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.View))
                        RetValue = true;
            return RetValue;
        }
        public bool HasPermissionViewItem(string Key)
        {
            bool RetValue = false;
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
                if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.View))
                    RetValue = true;
            return RetValue;
        }
        public bool HasPermissionAdd(string Key)
        {
            bool RetValue = false;
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
                if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.AddNewItem))
                    RetValue = true;
            return RetValue;
        }
        public bool HasPermissionEditItem(string Key)
        {
            bool RetValue = false;
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
                if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.EditItem))
                    RetValue = true;
            return RetValue;
        }
        public string RenderMenuBottom(string Key, string GroupID)
        {
            StringBuilder Html = new StringBuilder();
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
            {
                if (dt.Rows[0]["IsAdd"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.AddNewItem))
                    {
                        Html.Append("<a href=\"javascript:" + dt.Rows[0]["Method"].ToString() + "('" + dt.Rows[0]["AddUC"].ToString() + "','AddNewItem','" + dt.Rows[0]["Width"].ToString() + "','" + dt.Rows[0]["Height"].ToString() + "');\" title=\"Thêm mới\"><img src=\"../images/icons/icon_add.gif\" border=\"0px\" /><b>Thêm Mới</b></a>");
                    }
                if (dt.Rows[0]["IsAdd"].ToString().Equals("2"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.AddNewItem))
                    {
                        Html.Append("&nbsp;&nbsp;&nbsp;<a href=\"javascript:" + dt.Rows[0]["Method"].ToString() + "('" + dt.Rows[0]["AddUC"].ToString() + "','" + GroupID + "','AddNewItem','" + dt.Rows[0]["Width"].ToString() + "','" + dt.Rows[0]["Height"].ToString() + "');\" title=\"" + dt.Rows[0]["Title"].ToString() + "\"><img src=\"../images/icons/icon_adduser.png\" border=\"0px\" /><b>" + dt.Rows[0]["Title"].ToString() + "</b></a>");
                    }
            }
            return Html.ToString();
        }
        public string RenderMenuAlowEdit(string Key)
        {
            StringBuilder Html = new StringBuilder();
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
            {
                if (dt.Rows[0]["IsEdit"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.EditItem))
                    {
                        Html.Append("<a href=\"javascript:void(0);\" onclick=\"javascript:" + dt.Rows[0]["Method"].ToString() + "();\" title=\"Sửa\"><img src=\"../images/icons/icon_edit.png\" border=\"0px\" /> <b>Sửa</b></a>&nbsp;&nbsp;&nbsp;");
                    }
            }
            return Html.ToString();
        }
        public string RenderMenuTop(string Key, string GroupID)
        {
            StringBuilder Html = new StringBuilder();
            DataTable dt = GetInfoModule(Key);
            if (dt != null)
            {
                if (dt.Rows[0]["IsAdd"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.AddNewItem))
                    {
                        Html.Append("<a href=\"javascript:" + dt.Rows[0]["Method"].ToString() + "('" + dt.Rows[0]["AddUC"].ToString() + "','AddNewItem','" + dt.Rows[0]["Width"].ToString() + "','" + dt.Rows[0]["Height"].ToString() + "');\" title=\"Thêm mới\"><img src=\"../images/icons/icon_add.gif\" border=\"0px\" /><b>Thêm Mới</b></a>");
                    }
                if (dt.Rows[0]["IsAdd"].ToString().Equals("2"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.AddNewItem))
                    {
                        Html.Append("<a href=\"javascript:" + dt.Rows[0]["Method"].ToString() + "('" + dt.Rows[0]["AddUC"].ToString() + "','" + GroupID + "','AddNewItem','" + dt.Rows[0]["Width"].ToString() + "','" + dt.Rows[0]["Height"].ToString() + "');\" title=\"" + dt.Rows[0]["Title"].ToString() + "\"><img src=\"../images/icons/icon_adduser.png\" border=\"0px\" /><b>" + dt.Rows[0]["Title"].ToString() + "</b></a>");
                    }
                if (dt.Rows[0]["IsEdit"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.EditItem))
                    {
                        Html.Append("&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" onclick=\"javascript:CallFuncEditItem();\" title=\"Sửa\"><img src=\"../images/icons/icon_edit.png\" border=\"0px\" /><b>Sửa</b> </a>\n");
                    }
                if (dt.Rows[0]["IsDelete"].ToString().Equals("1"))
                    if (SecurityServices.HasPermission(dt.Rows[0]["TableName"].ToString(), SecurityServices.GetCurrentUser(), TypeAudit.DeleteItem))
                    {
                        Html.Append("&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" onclick=\"javascript:CallFuncDeleteItem();\" title=\"Xóa\"><img src=\"../images/icons/icon_delete.jpg\" border=\"0px\" /><b>Xóa</b> </a>\n");
                    }
            }
            return Html.ToString();
        }
        #endregion
        //ok
        #region TableManager - GetData
        public DataTable Manager_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "Order By LastLogin desc, CountLogin desc ";
            string Query = "Select ID,UserName,Password, Email, FullName,Address,BirthDay,Sex, " +
                        "	Case Sex When 0 Then N'Nữ' When 1 Then N'Nam' End as _Sex, " +
                        "	CountLogin, Created, LastLogin, Active, " +
                        "	Case Active When 0 Then N'Khóa' When 1 Then N'Hoạt động' End as _Active, LockedReason  " +
                        "From tbl_Manager " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }

        public DataTable Customer_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;

            string Query =
                "   Select "+
                " [CustommerID]" +
                ",[LoginName]" +
                ",[Password]" +
                ",[Email]" +
                ",[FullName]" +
                ",[PhoneNumber]" +
                ",[Address]" +
                ",[Sex]" +
                ",[Birthday]" +
                ",[MoreInfo]" +
                ",[Created]" +
                ",[CountLogin]" +
                ",[LastLogin]" +
                ",[Active], " +
                "	Case Sex When 'Nu' Then N'Nữ' When 'Nam' Then N'Nam' End as _Sex, " +
                "	Case Active When 0 Then N'Khóa' When 1 Then N'Hoạt động' End as _Active   " +
                "From tbl_Custommers ";  
             
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }


        public DataTable Customer_GetListEng(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;

            string Query =
                "   Select " +
                " [CustommerID]" +
                ",[LoginName]" +
                ",[Password]" +
                ",[Email]" +
                ",[FullName]" +
                ",[PhoneNumber]" +
                ",[Address]" +
                ",[Sex]" +
                ",[Birthday]" +
                ",[MoreInfo]" +
                ",[Created]" +
                ",[CountLogin]" +
                ",[LastLogin]" +
                ",[Active], " +
                "	Case Sex When 'Nu' Then N'Female' When 'Nam' Then N'Male' End as _Sex, " +
                "	Case Active When 0 Then N'Locl' When 1 Then N'Active' End as _Active   " +
                "From tbl_Custommers ";

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }


        public void Manager_DeleteItem(Guid ItemID)
        {
            string Query = "Delete From tbl_Manager" +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Manager_GetTitle(Guid itemid)
        {
            string Value = string.Empty;
            string Query = "Select FullName From tbl_Manager" +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Manager_GetUserName(Guid itemid)
        {
            string Value = string.Empty;
            string Query = "Select UserName From tbl_Manager" +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Manager_Search(string Keyword)
        {
            string Query = "Select ID,UserName,Password, Email, FullName,Address,BirthDay,Sex, " +
                        "	Case Sex When 0 Then N'Nữ' When 1 Then N'Nam' End as _Sex, " +
                        "	CountLogin, Created, LastLogin, Active, " +
                        "	Case Active When 0 Then N'Khóa' When 1 Then N'Hoạt động' End as _Active, LockedReason  " +
                        "From tbl_Manager " +
                        "Where UserName like N'%'+@Keyword+'%' or Email like N'%'+@Keyword+'%' or FullName like N'%'+@Keyword+'%' " +
                        "   or Address like N'%'+@Keyword+'%' " +
                        "Order By LastLogin desc, CountLogin desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Manager_InsertItem(Guid ID, string UserName, string Password, string Email, string FullName, string Address, DateTime BirthDay, int Sex, int CountLogin, DateTime Created, DateTime LastLogin, int Active, string LockedReason)
        {
            string Query = "Insert Into tbl_Manager( " +
                        "ID, UserName,Password,Email,FullName,Address,BirthDay,Sex,CountLogin,Created,LastLogin,Active,LockedReason) " +
                        "Values(@ID,@UserName,@Password,@Email,@FullName,@Address,@BirthDay,@Sex,@CountLogin,@Created,@LastLogin,@Active,@LockedReason) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@UserName", SqlDbType.VarChar),
                    new SqlParameter("@Password", SqlDbType.VarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@BirthDay", SqlDbType.DateTime),
                    new SqlParameter("@Sex", SqlDbType.Int),
                    new SqlParameter("@CountLogin", SqlDbType.Int),
                    new SqlParameter("@Created", SqlDbType.DateTime),
                    new SqlParameter("@LastLogin", SqlDbType.DateTime),
                    new SqlParameter("@Active", SqlDbType.Int),
                    new SqlParameter("@LockedReason", SqlDbType.NVarChar)};
            arrParam[0].Value = ID;
            arrParam[1].Value = UserName;
            arrParam[2].Value = Password;
            arrParam[3].Value = Email;
            arrParam[4].Value = FullName;
            arrParam[5].Value = Address;
            arrParam[6].Value = BirthDay;
            arrParam[7].Value = Sex;
            arrParam[8].Value = CountLogin;
            arrParam[9].Value = Created;
            arrParam[10].Value = LastLogin;
            arrParam[11].Value = Active;
            arrParam[12].Value = LockedReason;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Manager_CheckUserName(string UserName)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_Manager " +
                           "Where LOWER(UserName)=LOWER(@UserName) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = UserName;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Manager_GetIDByUserName(string UserName)
        {
            string Value = string.Empty;
            string Query = "Select ID From tbl_Manager " +
                           "Where LOWER(UserName)=LOWER(@UserName) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = UserName;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Manager_ViewItemByID(Guid ID)
        {
            string Query = "Select ID, UserName,Password, Email, FullName,Address,BirthDay,Sex, " +
                        "	Case Sex When 0 Then N'Nữ' When 1 Then N'Nam' End as _Sex, " +
                        "	CountLogin, Created, LastLogin, Active, " +
                        "	Case Active When 0 Then N'Khóa' When 1 Then N'Hoạt động' End as _Active, LockedReason  " +
                        "From tbl_Manager " +
                        "	Where ID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = ID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }

       

        public void Manager_UpDateItem(Guid ID, string Password, string Email, string FullName, string Address, DateTime BirthDay, int Sex, int Active, string LockedReason)
        {
            string Query = string.Empty;
            if (!string.IsNullOrEmpty(Password))
            {
                Query = "Update tbl_Manager " +
                        "Set " +
                        "	Password=@Password, " +
                        "	Email=@Email, " +
                        "	FullName=@FullName, " +
                        "	Address=@Address, " +
                        "	BirthDay=@BirthDay, " +
                        "	Sex=@Sex,	 " +
                        "	Active=@Active, " +
                        "	LockedReason=@LockedReason " +
                        "Where ID=@ID";
            }
            else
            {
                Query = "Update tbl_Manager " +
                            "Set " +
                            "	Email=@Email, " +
                            "	FullName=@FullName, " +
                            "	Address=@Address, " +
                            "	BirthDay=@BirthDay, " +
                            "	Sex=@Sex,	 " +
                            "	Active=@Active, " +
                            "	LockedReason=@LockedReason " +
                            "Where ID=@ID";
            }

            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@Password", SqlDbType.VarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@BirthDay", SqlDbType.DateTime),
                    new SqlParameter("@Sex", SqlDbType.Int),                                  
                    new SqlParameter("@Active", SqlDbType.Int),
                    new SqlParameter("@LockedReason", SqlDbType.NVarChar)};
            arrParam[0].Value = ID;
            arrParam[1].Value = Password;
            arrParam[2].Value = Email;
            arrParam[3].Value = FullName;
            arrParam[4].Value = Address;
            arrParam[5].Value = BirthDay;
            arrParam[6].Value = Sex;
            arrParam[7].Value = Active;
            arrParam[8].Value = LockedReason;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Manager_UpDateItemByUser(Guid ID, string Email, string FullName, string Address, DateTime BirthDay, int Sex)
        {
            string Query = "Update tbl_Manager " +
                            "Set " +
                            "	Email=@Email, " +
                            "	FullName=@FullName, " +
                            "	Address=@Address, " +
                            "	BirthDay=@BirthDay, " +
                            "	Sex=@Sex  " +
                            "Where ID=@ID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.UniqueIdentifier),                 
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@BirthDay", SqlDbType.DateTime),
                    new SqlParameter("@Sex", SqlDbType.Int)};
            arrParam[0].Value = ID;
            arrParam[1].Value = Email;
            arrParam[2].Value = FullName;
            arrParam[3].Value = Address;
            arrParam[4].Value = BirthDay;
            arrParam[5].Value = Sex;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Manager_CheckLogin(string UserName, string Password, DateTime LastLogin)
        {
            //81DC9BDB52D04DC20036DBD8313ED055
            string Value = string.Empty;
            string Query = "Declare @Output int, @CheckUserName int, @CheckPassword int, @CheckActive int " +
                    "Select @CheckUserName=isnull(Count(*),0) From tbl_Manager nv Where nv.UserName=@UserName " +
                    "if @CheckUserName=0 Set @Output=1 " +
                    "Else " +
                    "	Begin " +
                    "		Select @CheckPassword=isnull(Count(*),0) From tbl_Manager nv " +
                    "		Where nv.UserName=@UserName and nv.Password=@Password " +
                    "		if @CheckPassword=0 Set @Output=1 " +
                    "		Else " +
                    "			Begin " +
                    "				Select @CheckActive=nv.Active From tbl_Manager nv " +
                    "				Where nv.UserName=@UserName " +
                    "				if @CheckActive<>1 Set @Output=2 " +
                    "				Else	 " +
                    "					Begin " +
                    "					Declare @CountLogin int " +
                    "						Select @CountLogin = nv.CountLogin From tbl_Manager nv " +
                    "						Where nv.UserName=@UserName " +
                    "						Update tbl_Manager " +
                    "						Set " +
                    "							CountLogin=@CountLogin+1, " +
                    "							LastLogin=@LastLogin " +
                    "						Where UserName=@UserName " +
                    "						if @@ERROR=0 " +
                    "						Set @Output=0 " +
                    "					end											 " +
                    "			end " +
                    "	end " +
                    "Select @Output As [Output] ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@UserName", SqlDbType.VarChar),
                    new SqlParameter("@Password", SqlDbType.VarChar),
                    new SqlParameter("@LastLogin", SqlDbType.DateTime)};
            arrParam[0].Value = UserName;
            arrParam[1].Value = Password;
            arrParam[2].Value = LastLogin;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Manager_ChangePass(Guid ID, string OldPassword, string NewPassword)
        {
            string Value = string.Empty;
            string Query = "Declare @CheckID int, @CheckPassword int, @Output nvarchar(500) " +
                        "Select @CheckID=Count(*) From tbl_Manager m Where m.ID=@ID " +
                        "if @CheckID=0 " +
                        "Begin " +
                        "	set @Output=N'Sai tên đăng nhập' " +
                        "end " +
                        "Else " +
                        "	Begin " +
                        "		Select @CheckPassword=Count(*) From tbl_Manager m Where m.ID=@ID and m.Password=@OldPassword " +
                        "		if @CheckPassword=0 " +
                        "		Begin " +
                        "			set @Output=N'Mật khẩu cũ chưa đúng' " +
                        "		end " +
                        "		Else " +
                        "			Begin " +
                        "				Update tbl_Manager " +
                        "				Set " +
                        "					Password=@NewPassword	 " +
                        "				Where ID=@ID " +
                        "				if @@ERROR=0 " +
                        "					set @Output=N'Cập nhật password thành công!'			 " +
                        "			end " +
                        "	end " +
                        "Select @Output As [Output] ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@OldPassword", SqlDbType.VarChar),
                    new SqlParameter("@NewPassword", SqlDbType.VarChar)};
            arrParam[0].Value = ID;
            arrParam[1].Value = OldPassword;
            arrParam[2].Value = NewPassword;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public string Manager_GetLockedReason(string UserName)
        {
            string Value = string.Empty;
            string Query = "Select LockedReason From tbl_Manager" +
                        " Where UserName=@UserName";
            SqlParameter[] arrParam ={
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = UserName;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        #endregion
        //ok
        #region TableContact - GetData
        //public DataTable Contact_Reading()
        //{
        //    string Query = "Select ID, FullName, Email, Address, PhoneNumber, Title, " +
        //                " Body=CASE WHEN LEN(Body) <= 70 THEN Body ELSE Left(Body,70)+'...' END, Created From tbl_Contact" +
        //                " Order By Created desc ";
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}
        public DataTable Contact_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = " Order By Created desc ";
            string Query = "Select ID, FullName, Email, Address, PhoneNumber, Title=CASE WHEN LEN(Title) <= 70 THEN Title ELSE Left(Title,70)+'...' END, " +
                        " Body=CASE WHEN LEN(Body) <= 70 THEN Body ELSE Left(Body,70)+'...' END, Created From tbl_Contact " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void Contact_DeleteItem(int ItemID)
        {
            string Query = "Delete From tbl_Contact " +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Contact_GetTitle(int itemid)
        {
            string Value = string.Empty;
            string Query = "Select Title From tbl_Contact " +
                        " Where ID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public void Contact_InsertItem(string FullName, string Email, string Address, string PhoneNumber, string Title, string Body, DateTime Created)
        {
            string Query = "Insert Into tbl_Contact( " +
                        "FullName,Email,Address,PhoneNumber,Title,Body,Created) " +
                        "Values(@FullName,@Email,@Address,@PhoneNumber,@Title,Body,@Created) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@PhoneNumber", SqlDbType.VarChar),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar),                 
                    new SqlParameter("@Created", SqlDbType.DateTime)};
            arrParam[0].Value = FullName;
            arrParam[1].Value = Email;
            arrParam[2].Value = Address;
            arrParam[3].Value = PhoneNumber;
            arrParam[4].Value = Title;
            arrParam[5].Value = Body;
            arrParam[6].Value = Created;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public void Contact_UpDateItem(int ID, string FullName, string Email, string Address, string PhoneNumber, string Title, string Body)
        {
            string Query = "Update tbl_Contact " +
                        "Set " +
                        "	FullName=@FullName, " +
                        "	Email=@Email, " +
                        "	Address=@Address, " +
                        "	PhoneNumber=@PhoneNumber, " +
                        "	Title=@Title, " +
                        "	Body=@Body	 " +
                        "Where ID=@ID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ID", SqlDbType.Int),
                    new SqlParameter("@FullName", SqlDbType.NVarChar),
                    new SqlParameter("@Email", SqlDbType.VarChar),
                    new SqlParameter("@Address", SqlDbType.NVarChar),
                    new SqlParameter("@PhoneNumber", SqlDbType.VarChar),
                    new SqlParameter("@Title", SqlDbType.NVarChar),
                    new SqlParameter("@Body", SqlDbType.NVarChar)};
            arrParam[0].Value = ID;
            arrParam[1].Value = FullName;
            arrParam[2].Value = Email;
            arrParam[3].Value = Address;
            arrParam[4].Value = PhoneNumber;
            arrParam[5].Value = Title;
            arrParam[6].Value = Body;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public DataTable Contact_ViewItemByID(int ItemID)
        {
            string Query = "Select ID, FullName, Email, Address, PhoneNumber, Title, " +
                        " Body, Created From tbl_Contact " +
                        "	Where ID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.Int)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable Contact_Search(string Keyword)
        {
            string Query = "Select ID, FullName, Email, Address, PhoneNumber, Title=CASE WHEN LEN(Title) <= 70 THEN Title ELSE Left(Title,70)+'...' END, " +
                        " Body=CASE WHEN LEN(Body) <= 70 THEN Body ELSE Left(Body,70)+'...' END, Created From tbl_Contact " +
                        "Where FullName like N'%'+@Keyword+'%' or Email like '%'+@Keyword+'%' or Address like N'%'+@Keyword+'%' " +
                        "or PhoneNumber like '%'+@Keyword+'%' or Title like N'%'+@Keyword+'%' or Body like N'%'+@Keyword+'%' " +
                        "Order By Created desc ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        #endregion
        //ok
        #region TableGroups - GetData
        public DataTable Groups_GetList(string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By GroupName ";
            string Query = "Select GroupID, GroupName, Description, IsAdmin, " +
                        "   Case IsAdmin When 0 Then N'Không' When '1' Then N'Có' End as _IsAdmin From tbl_Groups " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public void Groups_DeleteItem(Guid ItemID)
        {
            string Query = "Delete From tbl_Groups" +
                        " Where GroupID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Groups_GetGroupName(Guid itemid)
        {
            string Value = string.Empty;
            string Query = "Select GroupName From tbl_Groups" +
                        " Where GroupID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Groups_Search(string Keyword)
        {
            string Query = "Select GroupID, GroupName, Description, IsAdmin, " +
                        "   Case IsAdmin When 0 Then N'Không' When '1' Then N'Có' End as _IsAdmin From tbl_Groups " +
                        "Where GroupName like N'%'+@Keyword+'%' or Description like N'%'+@Keyword+'%' " +
                        "Order By GroupName ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Groups_InsertItem(Guid GroupID, string GroupName, string Description, bool IsAdmin)
        {
            string Query = "Insert Into tbl_Groups( " +
                        "GroupID,GroupName,Description,IsAdmin) " +
                        "Values(@GroupID,@GroupName,@Description,@IsAdmin) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier), 
                    new SqlParameter("@GroupName", SqlDbType.NVarChar), 
                    new SqlParameter("@Description", SqlDbType.NVarChar), 
                    new SqlParameter("@IsAdmin", SqlDbType.Bit)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = GroupName;
            arrParam[2].Value = Description;
            arrParam[3].Value = IsAdmin;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string Groups_CheckGroupName(string GroupName)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_Groups " +
                           "Where LOWER(GroupName)=LOWER(@GroupName) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupName", SqlDbType.NVarChar)};
            arrParam[0].Value = GroupName;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable Groups_ViewItemByID(Guid ItemID)
        {
            string Query = "Select GroupID, GroupName, Description, IsAdmin From tbl_Groups " +
                        "	Where GroupID=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void Groups_UpDateItem(Guid GroupID, string GroupName, string Description, bool IsAdmin)
        {
            string Query = "Update tbl_Groups " +
                        "Set " +
                        "	GroupName=@GroupName, " +
                        "	Description=@Description, " +
                        "	IsAdmin=@IsAdmin " +
                        "Where GroupID=@GroupID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@GroupName", SqlDbType.NVarChar),  
                    new SqlParameter("@Description", SqlDbType.NVarChar),         
                    new SqlParameter("@IsAdmin", SqlDbType.Bit)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = GroupName;
            arrParam[2].Value = Description;
            arrParam[3].Value = IsAdmin;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        #endregion
        //ok
        #region TableGroupUser - GetData
        public DataTable GroupUser_GetList()
        {
            string Query = "Select GroupID, UserName From tbl_GroupUser " +
                        "   Order By UserName ";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        public DataTable GroupUser_GetListByGroupID(Guid GroupID, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("m", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By m.UserName ";
            string Query = "Select gu.GroupID, m.UserName, m.ID, m.FullName From tbl_GroupUser gu JOIN tbl_Manager m ON gu.UserName = m.UserName " +
                        "  Where gu.GroupID=@GroupID " +
                        OrderBy;
            DataTable dtResult = new DataTable();
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier)};
            arrParam[0].Value = GroupID;
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void GroupUser_DeleteItem(Guid GroupID, string ItemID)
        {
            string Query = "Delete From tbl_GroupUser" +
                        " Where GroupID=@GroupID and UserName=@ItemID ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = ItemID;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string GroupUser_GetGroupName(Guid itemid)
        {
            string Value = string.Empty;
            string Query = "Select GroupName From tbl_Groups" +
                        " Where GroupID=@ItemID";
            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = itemid;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        public DataTable GroupUser_Search(Guid GroupID, string Keyword)
        {
            string Query = "Select gu.GroupID, gu.UserName, m.ID, m.FullName From tbl_GroupUser gu JOIN tbl_Manager m ON gu.UserName = m.UserName " +
                        "Where gu.GroupID = @GroupID and (gu.UserName like N'%'+@Keyword+'%' or m.FullName like N'%'+@Keyword+'%') " +
                        "Order By gu.UserName ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@Keyword", SqlDbType.NVarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = Keyword;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public void GroupUser_InsertItem(Guid GroupID, string UerName)
        {
            string Query = "Insert Into tbl_GroupUser( " +
                        "GroupID,UserName) " +
                        "Values(@GroupID,@UserName) ";
            SqlParameter[] arrParam ={
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),                             
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = UerName;
            DB.ExeCuteSqlParam(Query, arrParam);
        }
        public string GroupUser_CheckUserName(Guid GroupID, string UserName)
        {
            string Value = string.Empty;
            string Query = "Select COUNT(*) From tbl_GroupUser " +
                           "Where LOWER(UserName)=LOWER(@UserName) and LOWER(GroupID)=LOWER(@GroupID) ";
            SqlParameter[] arrParam ={                                         
                    new SqlParameter("@GroupID", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@UserName", SqlDbType.VarChar)};
            arrParam[0].Value = GroupID;
            arrParam[1].Value = UserName;
            Value = DB.ExeCuteScalarParam(Query, arrParam);
            return Value;
        }
        //public DataTable GroupUser_ViewItemByID(int ItemID)
        //{
        //    string Query = "Select GroupID, UserName From tbl_GroupUser " +
        //                "	Where GroupID=@ItemID ";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@ItemID", SqlDbType.Int)};
        //    arrParam[0].Value = ItemID;
        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableParam(Query, arrParam);
        //    return dtResult;
        //}
        //public void GroupUser_UpDateItem(int GroupID, string UserName, string GroupName)
        //{
        //    string Query = "Update tbl_GroupUser " +
        //                "Set " +
        //                "	UserName=@UserName, " +
        //                "	GroupName=@GroupName " +
        //                "Where GroupID=@GroupID";
        //    SqlParameter[] arrParam ={
        //            new SqlParameter("@GroupID", SqlDbType.Int),
        //            new SqlParameter("@UserName", SqlDbType.VarChar),                               
        //            new SqlParameter("@GroupName", SqlDbType.NVarChar)};
        //    arrParam[0].Value = GroupID;
        //    arrParam[1].Value = UserName;
        //    arrParam[2].Value = GroupName;
        //    DB.ExeCuteSqlParam(Query, arrParam);
        //}
        #endregion
        //ok
        #region SysTable - GetData
        public DataTable SysTabel_GetListName()
        {
            string Query = "SELECT name FROM sys.Tables WHERE name<>'sysdiagrams' ORDER BY name ";
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }
        #endregion

        public string RenderBaner(string siteid, bool isLogin)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"header\">\n" +

                "<div id=\"logo\">" +
                    "<a href=\"Home.html\"><img src=\"" + EnvInfo.HttpRoot + "images/static/" + "logo.png\"></a>" +
                "</div>" +

                "	<div id=\"banner\">\n");
            DataTable dt = Banner_GetTop1Item();
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["FileType"].ToString() == "Image")
                {
                    Html.Append(
                 "		<a href=\"javascript:void(0);\"><img src=\"" + EnvInfo.HttpRoot + "images/static/" + dt.Rows[0]["FileName"].ToString() + "\" /></a>\n");
                }
                else
                {
                    Html.Append("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'\n" +
                                " style='height: 62px' width='447px'>\n" +
                                " <param name='movie'\n" +
                                " value='ImageBanner/" + dt.Rows[0]["FileName"].ToString() + "' />\n" +
                                " <param name='quality' value='high' />\n" +
                                " <embed height='62 pluginspage='http://www.macromedia.com/go/getflashplayer' quality='high'\n" +
                                " src='" + EnvInfo.HttpRoot + "smallimages/" + dt.Rows[0]["FileName"].ToString() + "' type='application/x-shockwave-flash' width='447'>\n" +
                                " </embed>\n" +
                                " </object>"
                                );
                }
            }
            Html.Append(
                "	</div>\n" +
                "	<div id=\"rightheader\">\n" +
                "		<div id=\"topmenu\">\n" +
                "			<ul>\n");
            DataTable dtMenuTop = Menu_GetMenuTop();
            string Text = "Login";
            string Href = "Login.aspx";
            if (isLogin)
            {
                Text = "Logout";
                Href = "Logout.aspx";
            }

            Html.Append(
                    "<li><a href=\"" + EnvInfo.HttpRoot + Href + "\">" + Text + "</a></li>\n");
            if (dtMenuTop.Rows.Count > 0)
            {
                for (int i = 0; i < dtMenuTop.Rows.Count; i++)
                {
                    Html.Append(
                            "<li><a href=\"" +EnvInfo.HttpRoot + dtMenuTop.Rows[i]["Url"] + "\">" + dtMenuTop.Rows[i]["Title"] + "</a></li>\n"
                            );
                }
            }
            Html.Append(
                "			</ul>\n" +
                "		</div>\n" +
                "		<div id=\"searchbox\">\n" +
                "			<input type=\"text\" onfocus=\"if(this.value=='enter key') this.value='';\" onblur=\"if(this.value=='') this.value='enter key';\" value=\"enter key\" size=\"20\" class=\"inputbox\" alt=\"Tìm kiếm\" maxlength=\"20\" id=\"mod_search_searchword\" name=\"searchword\" onkeypress=\"javascript:DoPressEnterSearch(event);\" /> \n" +
                "		</div>\n" +
                "	</div>\n" +
                "	<br class=\"clrfix\" />\n" +
                "</div>\n"
                );

            return Html.ToString();
        }

        [AjaxPro.AjaxMethod]
        public string BuildUrlSearch(string keyword, string siteid)
        {
            //return EnvInfo.MainPublicRoot + siteid + "/search/" + keyword + ".html";
            return EnvInfo.HttpRoot + "search.aspx?key=" + keyword;
        }

        public string RenderFilterProducts(string siteid)
        {
            StringBuilder Html = new StringBuilder();
            //Html.Append(
            ////"<div id=\"rightcol\">\n"+
            //"	<h4 class=\"heading\">LỌC TÌM NHANH</h4>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>THEO GIÁ</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"textlist\">\n"+
            //"				<li><a href=\"#\">7,000,000 -> 10,000,000 <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">7,000,000 -> 10,000,000 <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">7,000,000 -> 10,000,000 <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">7,000,000 -> 10,000,000 <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">7,000,000 -> 10,000,000 <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">7,000,000 -> 10,000,000 <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">30,000,000 -> 50,000,000 <span>(45)</span></a></li>\n"+
            //"			</ul>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>THƯƠNG HIỆU</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<table class=\"logolist\">\n"+
            //"				<tr>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/1.png\" /></a></td>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/2.png\" /></a></td>\n"+
            //"				</tr>\n"+
            //"				<tr>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/3.png\" /></a></td>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/4.png\" /></a></td>\n"+
            //"				</tr>\n"+
            //"				<tr>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/5.png\" /></a></td>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/4.png\" /></a></td>\n"+
            //"				</tr>\n"+
            //"				<tr>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/1.png\" /></a></td>\n"+
            //"					<td><a href=\"#\"><img src=\"images/logo/2.png\" /></a></td>\n"+
            //"				</tr>\n"+
            //"			</table>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>CPU</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"arrowlist\">\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+

            //"			</ul>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>Ổ đĩa cứng</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"arrowlist\">\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+

            //"			</ul>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>Tốc độ</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"arrowlist\">\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+

            //"			</ul>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>Bộ nhớ RAM</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"arrowlist\">\n"+
            //"				<li><a href=\"#\">> 4 Gb <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">> 2 Gb <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\"> 1 Gb <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">< 1 Gb<span>(171)</span></a></li>\n"+

            //"			</ul>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>Màn hình</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"arrowlist\">\n"+
            //"				<li><a href=\"#\">Intel Core 2 Duo<span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Core i <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Intel Atom <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+

            //"			</ul>\n"+
            //"		</div>\n"+
            //"	</div>\n"+
            //"	<div class=\"searchmodule\">\n"+
            //"		<h5 class=\"heading\"><span>Card màn hình</span></h5>\n"+
            //"		<div class=\"searchbody\">\n"+
            //"			<ul class=\"arrowlist\">\n"+
            //"				<li><a href=\"#\">VIA C7-M <span>(171)</span></a></li>\n"+
            //"				<li><a href=\"#\">Centrino 2 Core 2 Duo <span>(171)</span></a></li>\n"+

            //"			</ul>\n"+
            //"		</div>\n"+
            ////"	</div>\n"+
            //"</div>\n"
            //);

            return Html.ToString();
        }
        public string RenderMenuBar(string siteid)
        {
            StringBuilder Html = new StringBuilder();
            //Html.Append("<div class=\"endheader\"></div>");
            //return Html.ToString();
            Html.Append(
                "	<div id=\"mainmenu\">		\n" +
                "	<ul>\n");
            DataTable dtMenubar = Menu_GetMenuBar();
            if (dtMenubar.Rows.Count > 0)
            {
                string cssActive = string.Empty;
                string Target = string.Empty;
                for (int i = 0; i < dtMenubar.Rows.Count; i++)
                {
                    if ((i + 1).ToString().Equals(siteid))
                        cssActive = "class=\"current\"";
                    else
                        cssActive = string.Empty;
                    if (dtMenubar.Rows[i]["Target"] != null && Convert.ToInt32(dtMenubar.Rows[i]["Target"]) == 1)
                        Target = "target=\"_blank\"";
                    else
                        Target = string.Empty;

                    if (i == dtMenubar.Rows.Count - 1)
                        cssActive = "class=\"end\"";

                    Html.Append(
                        "		<li " + cssActive + "><a href=\"" + EnvInfo.HttpRoot + dtMenubar.Rows[i]["Url"].ToString() + "\" " + Target + ">" + dtMenubar.Rows[i]["Title"].ToString() + "</a>\n"
                        );
                    DataTable dtMenuChild = Menu_GetMenuChild(Convert.ToInt32(dtMenubar.Rows[i]["MenuID"]));
                    if (dtMenuChild.Rows.Count > 0)
                    {
                        Html.Append("<ul>\n");
                        for (int j = 0; j < dtMenuChild.Rows.Count; j++)
                        {
                            Target = string.Empty;
                            Html.Append(
                                "				<li><a href=\"" + EnvInfo.HttpRoot + dtMenuChild.Rows[j]["Url"].ToString() + " \"  " + Target + ">" + dtMenuChild.Rows[j]["Title"] + "</a></li>\n"
                                );
                        }
                        Html.Append("</ul>\n");
                    }
                    Html.Append("</li>\n");
                }
            }
            Html.Append(
                "	</ul>\n" +
                "	</div>\n");
            return Html.ToString();
        }
        public string RenderHotNews(string siteid, int totalItem, string LoginName, bool isLogin)
        {
            StringBuilder Html = new StringBuilder();

            Html.Append(
                //    "<div id=\"hotnews\">\n" +
                //    "	<div class=\"title\">\n" +
                //    "		<h3><a href=\"javascript:void(0);\">" + MyResource.HotNews.ToUpper() + ": </a></h3>\n" +
                //    "	</div>\n" +
                //    "	<div class=\"newsscroll\">\n" +
                //    "		<ul>\n");
                //DataTable dthotnews = News_GetHotNews();
                //if (dthotnews.Rows.Count > 0)
                //{
                //    string HotnewsPublishDate = string.Empty;
                //    string HotnewsUrl = string.Empty;
                //    string HotnewsTitle = string.Empty;
                //    for (int i = 0; i < dthotnews.Rows.Count; i++)
                //    {
                //        HotnewsTitle = dthotnews.Rows[i]["Title"].ToString();
                //        HotnewsPublishDate = Convert.ToDateTime(dthotnews.Rows[i]["Created"]).ToString("dd-MM-yyyy");
                //        HotnewsUrl = Screen.BuildUrlForNewsDetails(dthotnews.Rows[i]["NewsID"].ToString(), HotnewsTitle,
                //                      dthotnews.Rows[i]["CateID"].ToString(), siteid);
                //        Html.Append(
                //            "			<li><a title=\"" + HotnewsTitle + "\" href=\"" + HotnewsUrl + "\"><span>" + HotnewsPublishDate + " > </span>" + HotnewsTitle + "</a></li>\n"
                //            );
                //    }
                //}
                //Html.Append(
                //  "		</ul>\n" +
                //  "	</div>\n" +
                //  "</div>\n" +
              "<div id=\"shoppingcart\">\n" +
              "    <a href=\"" + EnvInfo.HttpRoot + "cart.html\">" + MyResource.MyCart + " (" + totalItem + " " + MyResource.Products + ")</a>" +
              "</div>\n");

            string href = string.Empty;
            string link = "Guest";
            if (isLogin)
            {
                href = "CustommerInfo.aspx";
                link = "<a href= " + href + ">" + LoginName + "</a>";
            }
            
            Html.Append(
              "<div id=\"customerinfo\">\n" +
              "" + MyResource.Hi + ", " + link +
              "</div>\n");

            return Html.ToString();
        }

        /// <summary>
        /// TODO:
        /// </summary>
        /// <param name="siteid"></param>
        /// <param name="PrefixSpecialSite"></param>
        /// <param name="catid"></param>
        /// <returns></returns>
        public string RenderProductByCategory(string cid, string sortby, string strDataAlias,
            int ItemsPerRow,
            int NoOfVisiblePage,
            int CurrentPage,
            string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divPrductByCateContent\" >\n" +
                BuildProductByCateContent(cid, sortby, strDataAlias, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID) +
                "</div>\n"
                );
            return Html.ToString();
        }

        public string RenderProductByFilter(string cid, string sortby, string strDataAlias,
            int ItemsPerRow,
            int NoOfVisiblePage,
            int CurrentPage,
            string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divPrductByCateContent\" >\n" +
                BuildProductByFilter(cid, sortby, strDataAlias, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID) +
                "</div>\n"
                );
            return Html.ToString();
        }

        [AjaxPro.AjaxMethod]
        public string BuildProductByCateContent(string CateID, string SortCondition, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = Products_GetItemsByCateID(int.Parse("0" + CateID), SortCondition);
            string PagingText = new Paging().GetPagingSearch(CateID, SortCondition, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID, ref StartIndex, ref EndIndex);
            string Title = string.Empty;
            try
            {
                Title = Category_GetTitle(int.Parse("0" + CateID));
            }
            catch { }
            Html.Append(
            "<div class=\"productcatwrap\">\n" +
            "	<h2 class=\"heading\">" + Title + "\n");
            if (dt.Rows.Count > 0)
                Html.Append(RenderSortIndex("IndexOfProductByCate", CateID, SortCondition, strDataAlias, 18, 10, 0, JumpJavaScript, SiteID));
            Html.Append(
            "	<br class=\"clrfix\" />\n" +
            "   </h2>\n" +
            "	<table class=\"productlist\">\n" +
            "			<tbody>\n");
            if (dt.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string ProductName = string.Empty;
                string Description = string.Empty;
                string KhuyenMai = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                float NewPriceProduct = 0;
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    try
                    {
                        if (dt.Rows[i]["Image"] != null)
                            ImageName = dt.Rows[i]["Image"].ToString();
                        else
                            ImageName = "no_image.jpg";
                    }
                    catch { }
                    try
                    {
                        if ((bool)dt.Rows[i]["Status"])
                            Status = MyResource.InStock;
                        else
                            Status = MyResource.OutStock;
                    }
                    catch { }
                    try
                    {
                        NewPriceProduct = Convert.ToInt64(dt.Rows[i]["NewPrice"]);
                    }
                    catch { }
                    try
                    {
                        KhuyenMai = dt.Rows[i]["KhuyenMai"].ToString();
                    }
                    catch { }
                    try
                    {
                        ProductUrl = Screen.BuildUrlForProductDetails(dt.Rows[i]["ProductID"].ToString(), dt.Rows[i]["ProductName"].ToString(), CateID, SiteID);
                    }
                    catch { }

                    if (i % 3 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "				<td>\n" +
                    "					<a href=\"" + ProductUrl + "\" class=\"thumb\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\"></a>\n" +
                    "					<div class=\"basicinfo\">\n" +
                    "						<h3><a href=\"" + ProductUrl + "\">" + dt.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "						<ul>\n" +
                    "							<li><span class=\"caption\">"+MyResource.ProductType+"</span>: " + dt.Rows[i]["Title"].ToString() + "</li>\n" +
                    "							<li><span class=\"caption\">"+MyResource.ProductStatus+"</span>: " + Status + "</li>\n" +
                    "							<li><span class=\"caption\">"+MyResource.ProductPrice+":</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "						</ul>\n" +
                    "					</div>\n" +
                    "					<div class=\"toolpro\">\n" +
                    "						<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dt.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "					</div>\n" +
                    "					<div class=\"moreinfo\">\n");
                    if (KhuyenMai.Length > 0)
                        Html.Append(
                    "						<b>"+MyResource.SaleInfomation+":</b> " + KhuyenMai + "\n");
                    Html.Append(
                    "					</div>\n" +
                    "				</td>\n"
                        );
                    if (i % 3 == 2)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dt.Rows.Count % 3 != 2)
                    Html.Append(
                    "				</tr>\n");
            }

            Html.Append(
                "		</tbody>\n" +
                "	</table>\n"
               );
            if (PagingText.Trim().Length > 0)
            {
                Html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            Html.Append(
                "	<br class=\"clrfix\" />\n" +
                "</div>\n"
                );
            return Html.ToString();
        }

        [AjaxPro.AjaxMethod]
        public string BuildProductByFilter(string CateID, string SortCondition, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = ReadingProductsByFilter(int.Parse(CateID));
            string PagingText = new Paging().GetPagingSearch(CateID, SortCondition, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID, ref StartIndex, ref EndIndex);
            string Title = string.Empty;
            try
            {
                Title = Category_GetTitle(int.Parse(CateID));
            }
            catch { }
            Html.Append(
            "<div class=\"productcatwrap\">\n" +
            "	<h2 class=\"heading\">" + Title + "\n");
            if (dt.Rows.Count > 0)
                Html.Append(RenderSortIndex("IndexOfProductByCate", CateID, SortCondition, strDataAlias, 18, 10, 0, JumpJavaScript, SiteID));
            Html.Append(
            "	<br class=\"clrfix\" />\n" +
            "   </h2>\n" +
            "	<table class=\"productlist\">\n" +
            "			<tbody>\n");
            if (dt.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string ProductName = string.Empty;
                string Description = string.Empty;
                string KhuyenMai = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                float NewPriceProduct = 0;
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    try
                    {
                        if (dt.Rows[i]["Image"] != null)
                            ImageName = dt.Rows[i]["Image"].ToString();
                        else
                            ImageName = "no_image.jpg";
                    }
                    catch { }
                    try
                    {
                        if ((bool)dt.Rows[i]["Status"])
                            Status = MyResource.InStock;
                        else
                            Status = MyResource.OutStock;
                    }
                    catch { }
                    try
                    {
                        NewPriceProduct = Convert.ToInt64(dt.Rows[i]["NewPrice"]);
                    }
                    catch { }
                    try
                    {
                        KhuyenMai = dt.Rows[i]["KhuyenMai"].ToString();
                    }
                    catch { }
                    try
                    {
                        ProductUrl = Screen.BuildUrlForProductDetails(dt.Rows[i]["ProductID"].ToString(), dt.Rows[i]["ProductName"].ToString(), CateID, SiteID);
                    }
                    catch { }

                    if (i % 3 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "				<td>\n" +
                    "					<a href=\"" + ProductUrl + "\" class=\"thumb\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\"></a>\n" +
                    "					<div class=\"basicinfo\">\n" +
                    "						<h3><a href=\"" + ProductUrl + "\">" + dt.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "						<ul>\n" +
                    "							<li><span class=\"caption\">" + MyResource.ProductType + "</span>: " + Title + "</li>\n" +
                    "							<li><span class=\"caption\">" + MyResource.ProductStatus + "</span>: " + Status + "</li>\n" +
                    "							<li><span class=\"caption\">" + MyResource.ProductPrice + ":</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "						</ul>\n" +
                    "					</div>\n" +
                    "					<div class=\"toolpro\">\n" +
                    "						<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dt.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "					</div>\n" +
                    "					<div class=\"moreinfo\">\n");
                    if (KhuyenMai.Length > 0)
                        Html.Append(
                    "						<b>" + MyResource.SaleInfomation + ":</b> " + KhuyenMai + "\n");
                    Html.Append(
                    "					</div>\n" +
                    "				</td>\n"
                        );
                    if (i % 3 == 2)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dt.Rows.Count % 3 != 2)
                    Html.Append(
                    "				</tr>\n");
            }

            Html.Append(
                "		</tbody>\n" +
                "	</table>\n"
               );
            if (PagingText.Trim().Length > 0)
            {
                Html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            Html.Append(
                "	<br class=\"clrfix\" />\n" +
                "</div>\n"
                );
            return Html.ToString();
        }

        public string RenderProductByMultiCategory(string cid, string sortby, string strDataAlias,
            int ItemsPerRow,
            int NoOfVisiblePage,
            int CurrentPage,
            string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                RenderListSubCate(cid, SiteID) 
                //"<div id=\"divPrductByMultiCateContent\" >\n" +
                //BuildProductByMultiCateContent(cid, sortby, strDataAlias, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID) +
                //"</div>\n"
                );
            return Html.ToString();
        }
        private string RenderListSubCate(string CateID, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div class=\"subcat\">\n" +
                "	<h6 class=\"heading\">"+MyResource.DishesCategory+"</h6>\n" +
                "	<ul>\n");
            DataTable dt = Category_GetSubItems(int.Parse("0" + CateID));
            if (dt.Rows.Count > 0)
            {
                string CategoryUrl = string.Empty;
                string Image = string.Empty;
                string CountProduct = "0";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    try
                    {
                        if (dt.Rows[i]["Image"] != null)
                            Image = dt.Rows[i]["Image"].ToString();
                        else
                            Image = "no_image.jpg";
                        if (string.IsNullOrEmpty(Image))
                            Image = "no_image.jpg";
                    }
                    catch { }
                    try
                    {
                        CountProduct = Products_GetTotalProductByCate(int.Parse("0" + dt.Rows[i]["CateID"].ToString()));
                    }
                    catch { }
                    try
                    {
                        CategoryUrl = Screen.BuildUrlForProductByCategory(dt.Rows[i]["Title"].ToString(), dt.Rows[i]["CateID"].ToString(), SiteID);
                    }
                    catch { }

                    Html.Append(
                        "		<li>\n" +
                        "		<a href=\"" + CategoryUrl + "\">\n" +
                        "			<img src=\"" + EnvInfo.HttpRoot + "smallimages/" + Image + "\" /><br />\n" +
                        "			<span class=\"title\">" + dt.Rows[i]["Title"].ToString() + " <em>(" + CountProduct + ")</em></span>\n" +
                        "		</a>\n" +
                        "		</li>\n");
                }
            }
            Html.Append(
                "		<br class=\"clrfix\" />\n" +
                "	</ul>\n" +
                "</div>\n"
                );
            return Html.ToString();
        }
        [AjaxPro.AjaxMethod]
        public string BuildProductByMultiCateContent(string CateID, string SortCondition, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = Products_GetItemsByCateID(int.Parse("0" + CateID), SortCondition);
            string PagingText = new Paging().GetPagingSearch(CateID, SortCondition, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID, ref StartIndex, ref EndIndex);
            string Title = string.Empty;
            try
            {
                Title = Category_GetTitle(int.Parse("0" + CateID));
            }
            catch { }
            Html.Append(
            "<div class=\"productcatwrap\">\n" +
            "	<h2 class=\"heading\">Sản phẩm mới\n");
            if (dt.Rows.Count > 0)
                Html.Append(RenderSortIndex("IndexOfProductByMultiCate", CateID, SortCondition, strDataAlias, 18, 10, 0, JumpJavaScript, SiteID));
            Html.Append(
            "	<br class=\"clrfix\" />\n" +
            "   </h2>\n" +
            "	<table class=\"productlist\">\n" +
            "			<tbody>\n");
            if (dt.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string ProductName = string.Empty;
                string Description = string.Empty;
                string KhuyenMai = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                float NewPriceProduct = 0;
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    try
                    {
                        if (dt.Rows[i]["Image"] != null)
                            ImageName = dt.Rows[i]["Image"].ToString();
                        else
                            ImageName = "no_image.jpg";
                    }
                    catch { }
                    try
                    {
                        if ((bool)dt.Rows[i]["Status"])
                            Status = "Còn hàng";
                        else
                            Status = "Hết hàng";
                    }
                    catch { }
                    try
                    {
                        NewPriceProduct = Convert.ToInt64(dt.Rows[i]["NewPrice"]);
                    }
                    catch { }
                    try
                    {
                        KhuyenMai = dt.Rows[i]["KhuyenMai"].ToString();
                    }
                    catch { }
                    try
                    {
                        ProductUrl = Screen.BuildUrlForProductDetails(dt.Rows[i]["ProductID"].ToString(), dt.Rows[i]["ProductName"].ToString(), CateID, SiteID);
                    }
                    catch { }

                    if (i % 3 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "				<td>\n" +
                    "					<a href=\"" + ProductUrl + "\" class=\"thumb\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\"></a>\n" +
                    "					<div class=\"basicinfo\">\n" +
                    "						<h3><a href=\"" + ProductUrl + "\">" + dt.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "						<ul>\n" +
                    "							<li><span class=\"caption\">Loại SP</span>: " + dt.Rows[i]["Title"].ToString() + "</li>\n" +
                    "							<li><span class=\"caption\">Tình trạng</span>: " + Status + "</li>\n" +
                    "							<li><span class=\"caption\">Giá bán:</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "						</ul>\n" +
                    "					</div>\n" +
                    "					<div class=\"toolpro\">\n" +
                    "						<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dt.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "					</div>\n" +
                    "					<div class=\"moreinfo\">\n");
                    if (KhuyenMai.Length > 0)
                        Html.Append(
                    "						<b>Thông tin khuyến mại:</b> " + KhuyenMai + "\n");
                    Html.Append(
                    "					</div>\n" +
                    "				</td>\n"
                        );
                    if (i % 3 == 2)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dt.Rows.Count % 3 != 2)
                    Html.Append(
                    "				</tr>\n");
            }

            Html.Append(
                "		</tbody>\n" +
                "	</table>\n"
               );
            if (PagingText.Trim().Length > 0)
            {
                Html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            Html.Append(
                "	<br class=\"clrfix\" />\n" +
                "</div>\n"
                );
            return Html.ToString();
        }
        public string RenderSlideImage()
        {
            StringBuilder Html = new StringBuilder();
            DataTable dtSlide = Adverts_SlideImageReading();
            Html.Append(
                "<div id=\"mainslidewrap\" class=\"w960\">\n" +
                "<div id=\"mainslide\">\n");
            if (dtSlide.Rows.Count > 0)
            {
                string Target = string.Empty;
                for (int i = 0; i < dtSlide.Rows.Count; i++)
                {
                    if (dtSlide.Rows[i]["Target"] != null && Convert.ToInt32(dtSlide.Rows[i]["Target"]) == 1)
                        Target = "target=\"_blank\"";
                    else
                        Target = string.Empty;
                    Html.Append(
                         "	<a href=\"" + dtSlide.Rows[i]["Url"].ToString() + "\" " + Target + "><img src=\"" + EnvInfo.HttpRoot + "images/" + dtSlide.Rows[i]["Image"].ToString() + "\" alt=\"" + dtSlide.Rows[i]["Description"].ToString() + "\" /></a>\n");
                }
            }
            Html.Append(
                "</div>\n" +
                "</div>\n"
                );
            return Html.ToString();
        }
        public string RenderSlideBottom()
        {
            StringBuilder Html = new StringBuilder();
            Html.Append("<div class = \"endbottom\"></div>");
            return Html.ToString();
            DataTable dtSlide = Adverts_SlideBottomReading();
            Html.Append(
                "<div id=\"advbottom\" class=\"w960\">\n");
            if (dtSlide.Rows.Count > 0)
            {
                string Target = string.Empty;
                if (dtSlide.Rows[0]["Target"] != null && Convert.ToInt32(dtSlide.Rows[0]["Target"]) == 1)
                    Target = "target=\"_blank\"";
                else
                    Target = string.Empty;
                Html.Append(
                "	<a href=\"" + dtSlide.Rows[0]["Url"].ToString() + "\" " + Target + "><img src=\"" + EnvInfo.HttpRoot + "images/logo/" + dtSlide.Rows[0]["Image"].ToString() + "\" alt=\"" + dtSlide.Rows[0]["Description"].ToString() + "\" /></a>\n");

            }
            Html.Append(
                "</div>\n");
            return Html.ToString();
        }
        public string RenderSupportBar()
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
            "<div id=\"support\" class=\"w960\"> \n" +
                "    <ul> \n");
            DataTable dtSupport = SupportOnline_Reading();
            if (dtSupport.Rows.Count > 0)
            {
                for (int i = 0; i < dtSupport.Rows.Count; i++)
                {
                    Html.Append(
                     "        <li><a class=\"cssOnlineSupport\" title=\"" + dtSupport.Rows[i]["Yahoo"].ToString() + "\" href=\"ymsgr:sendim?" + dtSupport.Rows[i]["Yahoo"].ToString() + "\">" + dtSupport.Rows[i]["Description"].ToString() + "<br /><img src=\"http://opi.yahoo.com/online?u=" + dtSupport.Rows[i]["Yahoo"].ToString() + "&amp;t=2\"></a></li> \n"
                    );
                }
            }
            Html.Append(
            "        <br class=\"clrfix\" /> \n" +
            "    </ul> \n" +
            "    <div class=\"hotline\"> \n" +
            "        <span class=\"hotlineicon\">Hotline: </span> \n");
            try
            {
                Html.Append(
                StatisNews_GetItemByTitle("Hotline"));
            }
            catch { }
            Html.Append(
            "    </div> \n" +
            "    <br class=\"clrfix\" /> \n" +
            "</div>");
            return Html.ToString();
        }
        public string RenderSellerProducts(string siteid)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div class=\"hotproduct\">\n" +
                "	<h3 class=\"title\">" + MyResource.HotProducts.ToUpper() + "</h3>\n" +
                "	<a class=\"prev1\" href=\"javascript:avoid()\"></a>\n" +
                "	<a class=\"next1\" href=\"javascript:avoid()\"></a>\n" +
                "	<div class=\"slider1\">\n" +
                "	<ul class=\"hscroll\">\n");

            DataTable dtProSeller = Products_SellerReading();
            if (dtProSeller.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                for (int i = 0; i < dtProSeller.Rows.Count; i++)
                {
                    if (dtProSeller.Rows[i]["Image"] != null)
                        ImageName = dtProSeller.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    float OldPrice = Convert.ToInt64(dtProSeller.Rows[i]["OldPrice"]);
                    if (OldPrice > 0)
                        OldPriceProduct = "			<span class=\"oldprice\">" + OldPrice.ToString("#,###") + "</span>\n";
                    float NewPriceProduct = Convert.ToInt64(dtProSeller.Rows[i]["NewPrice"]);
                    ProductUrl = Screen.BuildUrlForProductDetails(dtProSeller.Rows[i]["ProductID"].ToString(), dtProSeller.Rows[i]["ProductName"].ToString(),
                                  dtProSeller.Rows[i]["CateID"].ToString(), siteid);
                    Html.Append(
                        "		<li><a " + Description + " href=\"" + ProductUrl + "\">\n" +
                        "			<img class=\"product_bestsell\" src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /><br />\n" +
                        "			<span class=\"name\">" + dtProSeller.Rows[i]["ProductName"].ToString() + "</span>\n" +
                                    OldPriceProduct +
                        "			<span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span>\n" +
                        "			</a>\n" +
                        "		</li>\n"
                        );
                }
            }
            Html.Append(
                "	</ul>\n" +
                "	<br class=\"clrfix\" />\n" +
                "	</div>\n" +
                "</div>\n"
                );
            return Html.ToString();
        }
        public string RenderKhuyenMaiProducts(string siteid)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div class=\"fproduct\">\n" +
                "	<h3 class=\"title\">" + MyResource.SaleProducts.ToUpper() + "</h3>\n" +
            //        "	<div class=\"morecat\">\n" +
            //        "		<ul>\n");
            //DataTable dtMenuKM = Menu_GetMenuKhuyenMai();
            //if (dtMenuKM.Rows.Count > 0)
            //{
            //    string cssAllcat = string.Empty;
            //    string Target = string.Empty;
            //    for (int i = 0; i < dtMenuKM.Rows.Count; i++)
            //    {
            //        if (dtMenuKM.Rows[i]["Target"] != null && Convert.ToInt32(dtMenuKM.Rows[i]["Target"]) == 1)
            //            Target = "target=\"_blank\"";
            //        else
            //            Target = string.Empty;
            //        if (dtMenuKM.Rows[i]["Title"].ToString().ToLower().Equals("" + MyResource.ViewAll + ""))
            //            cssAllcat = "class=\"allcat\"";
            //        Html.Append(
            //    "			<li " + cssAllcat + "><a href=\"javascript:void(0);\"  onclick=\"javascript:ClientGetDiscountProductsByMenu(" + siteid + ", " + dtMenuKM.Rows[i]["Description"].ToString().Trim() + ");\" >" + dtMenuKM.Rows[i]["Title"].ToString() + "</a></li>\n"
            //            );
            //    }
            //}
            //Html.Append(
            //    "		</ul>\n" +
            //    "	</div>\n" +

            "<div class=\"morecat\">\n" +
"							<ul>\n" +
"								<li class=\"allcat\"><a href=\"#\">Xem toàn bộ</a></li>\n" +
"								<li><a href=\"#\">Sản phẩm điện thoại</a></li>\n" +
"								<li><a href=\"#\">Phụ kiện</a></li>\n" +
"								<li><a href=\"#\">Laptop</a></li>\n" +
"							</ul>\n" +
"						</div>\n" +

                "	<div class=\"productwrapper\" id=\"divDiscountProducts\">\n" +
                "			<table class=\"productlist\">\n");
            DataTable dtproduct = Products_KhuyenMaiReading();
            if (dtproduct.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                for (int i = 0; i < dtproduct.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(dtproduct.Rows[i]["Image"].ToString()))
                        ImageName = dtproduct.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    if ((bool)dtproduct.Rows[i]["Status"])
                        Status = MyResource.InStock;
                    else
                        Status = MyResource.OutStock;
                    float NewPriceProduct = Convert.ToInt64(dtproduct.Rows[i]["NewPrice"]);
                    ProductUrl = Screen.BuildUrlForProductDetails(dtproduct.Rows[i]["ProductID"].ToString(), dtproduct.Rows[i]["ProductName"].ToString(),
                                  dtproduct.Rows[i]["CateID"].ToString(), siteid);
                    if (i == 0 || i == 4 || i == 8)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "					<td>\n" +
                    "						<a class=\"thumb\" href=\"" + ProductUrl + "\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                    "						<div class=\"basicinfo\">\n" +
                    "							<h3><a href=\"" + ProductUrl + "\">" + dtproduct.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "							<ul>\n" +
                    "								<li><span class=\"caption\">" + MyResource.ProductType + "</span>: " + dtproduct.Rows[i]["Title"].ToString() + "</li>\n" +
                    "								<li><span class=\"caption\">" + MyResource.ProductStatus + "</span>: " + Status + "</li>\n" +
                    "								<li><span class=\"caption\">" + MyResource.ProductPrice + ":</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "							</ul>\n" +
                    "						</div>\n" +
                    "						<div class=\"toolpro\">\n" +
                    "							<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dtproduct.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "						</div>\n" +
                    "						<div class=\"moreinfo\">\n" +
                    "							<b>" + MyResource.SaleInfomation + ":</b>" + dtproduct.Rows[i]["KhuyenMai"].ToString() + "\n" +
                    "						</div>\n" +
                    "					</td>\n"
                        );
                    if (i == 3 || i == 7 || i == 11)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dtproduct.Rows.Count < 3)
                    Html.Append(
                    "				</tr>\n");
                if (dtproduct.Rows.Count > 3 && dtproduct.Rows.Count < 7)
                    Html.Append(
                    "				</tr>\n");
                if (dtproduct.Rows.Count > 7 && dtproduct.Rows.Count < 11)
                    Html.Append(
                    "				</tr>\n");
            }
            Html.Append(
               "			</table>\n" +
               "	</div>\n" +
               "	<br class=\"clrfix\" />\n" +
               "</div>\n"
               );
            return Html.ToString();
        }
        [AjaxPro.AjaxMethod]
        public string RenderKhuyenMaiProductsByMenu(string siteid, string catid)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append("			<table class=\"productlist\">\n");
            DataTable dtproduct = GetProducts_KhuyenMaiReading(catid);
            if (dtproduct.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                for (int i = 0; i < dtproduct.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(dtproduct.Rows[i]["Image"].ToString()))
                        ImageName = dtproduct.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    if ((bool)dtproduct.Rows[i]["Status"])
                        Status = "Còn hàng";
                    else
                        Status = "Hết hàng";
                    float NewPriceProduct = Convert.ToInt64(dtproduct.Rows[i]["NewPrice"]);
                    ProductUrl = Screen.BuildUrlForProductDetails(dtproduct.Rows[i]["ProductID"].ToString(), dtproduct.Rows[i]["ProductName"].ToString(),
                                  dtproduct.Rows[i]["CateID"].ToString(), siteid);
                    if (i == 0 || i == 4 || i == 8)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "					<td>\n" +
                    "						<a class=\"thumb\" href=\"" + ProductUrl + "\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                    "						<div class=\"basicinfo\">\n" +
                    "							<h3><a href=\"" + ProductUrl + "\">" + dtproduct.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "							<ul>\n" +
                    "								<li><span class=\"caption\">Loại SP</span>: " + dtproduct.Rows[i]["Title"].ToString() + "</li>\n" +
                    "								<li><span class=\"caption\">Tình trạng</span>: " + Status + "</li>\n" +
                    "								<li><span class=\"caption\">Giá bán:</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "							</ul>\n" +
                    "						</div>\n" +
                    "						<div class=\"toolpro\">\n" +
                    "							<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dtproduct.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "						</div>\n" +
                    "						<div class=\"moreinfo\">\n" +
                    "							<b>Thông tin khuyến mại:</b>" + dtproduct.Rows[i]["KhuyenMai"].ToString() + "\n" +
                    "						</div>\n" +
                    "					</td>\n"
                        );
                    if (i == 3 || i == 7 || i == 11)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dtproduct.Rows.Count < 3)
                    Html.Append(
                    "				</tr>\n");
                if (dtproduct.Rows.Count > 3 && dtproduct.Rows.Count < 7)
                    Html.Append(
                    "				</tr>\n");
                if (dtproduct.Rows.Count > 7 && dtproduct.Rows.Count < 11)
                    Html.Append(
                    "				</tr>\n");
            }
            else
            {
                Html.Append("<tr><td>Hiện chưa có sản phẩm nào thuộc nhóm này</td></tr>\n");
            }
            Html.Append(
               "			</table>\n" +
               "	</div>\n" +
               "	<br class=\"clrfix\" />\n"
                //"</div>\n"
               );
            return Html.ToString();
        }
        public string RenderNewProducts(string siteid)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div class=\"nproduct\">\n" +
                "	<h3 class=\"title\">" + MyResource.NewProducts.ToUpper() + "</h3>\n" +
                    "	<div class=\"morecat\">\n" +
                    "		<ul>\n");
            DataTable dtMenuNewPro = Menu_GetMenuNewProducts();
            if (dtMenuNewPro.Rows.Count > 0)
            {
                string cssAllcat = string.Empty;
                string Target = string.Empty;
                for (int i = 0; i < dtMenuNewPro.Rows.Count; i++)
                {
                    if (dtMenuNewPro.Rows[i]["Target"] != null && Convert.ToInt32(dtMenuNewPro.Rows[i]["Target"]) == 1)
                        Target = "target=\"_blank\"";
                    else
                        Target = string.Empty;
                    if (dtMenuNewPro.Rows[i]["Title"].ToString().ToLower().Equals("" + MyResource.ViewAll + ""))
                        cssAllcat = "class=\"allcat\"";//<li class=\"allcat\"><a href=\"#\">Xem toàn bộ</a></li>\n"+
                    Html.Append(
                "			<li " + cssAllcat + "><a href=\"javascript:void(0);\" onclick=\"javascript:ClientGetProductsByMenu(" + siteid + ", " + dtMenuNewPro.Rows[i]["Description"].ToString().Trim() + ");\">" + dtMenuNewPro.Rows[i]["Title"].ToString() + "</a></li>\n"
                        );
                }
            }
            Html.Append(
                "		</ul>\n" +
                "	</div>\n" +
                "	<div class=\"productwrapper\">\n" +
                "		<table class=\"productlist\"  id=\"divNewProducts\" >\n");
            DataTable dtproduct = Products_NewReading();
            if (dtproduct.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                for (int i = 0; i < dtproduct.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(dtproduct.Rows[i]["Image"].ToString()))
                        ImageName = dtproduct.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    if ((bool)dtproduct.Rows[i]["Status"])
                        Status = MyResource.InStock;
                    else
                        Status = MyResource.OutStock;
                    float NewPriceProduct = Convert.ToInt64(dtproduct.Rows[i]["NewPrice"]);
                    ProductUrl = Screen.BuildUrlForProductDetails(dtproduct.Rows[i]["ProductID"].ToString(), dtproduct.Rows[i]["ProductName"].ToString(),
                                  dtproduct.Rows[i]["CateID"].ToString(), siteid);
                    if (i % 4 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "					<td>\n" +
                    "						<a class=\"thumb\" href=\"" + ProductUrl + "\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                    "						<div class=\"basicinfo\">\n" +
                    "							<h3><a href=\"" + ProductUrl + "\">" + dtproduct.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "							<ul>\n" +
                    "								<li><span class=\"caption\">" + MyResource.ProductType + "</span>: " + dtproduct.Rows[i]["Title"].ToString() + "</li>\n" +
                    "								<li><span class=\"caption\">" + MyResource.ProductStatus + "</span>: " + Status + "</li>\n" +
                    "								<li><span class=\"caption\">" + MyResource.ProductPrice + ":</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "							</ul>\n" +
                    "						</div>\n" +
                    "						<div class=\"toolpro\">\n" +
                    "							<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dtproduct.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "						</div>\n" +
                    "					</td>\n"
                        );
                    if (i % 4 == 3)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dtproduct.Rows.Count % 4 != 3)
                    Html.Append(
                    "				</tr>\n");
            }

            Html.Append(
                "			</table>\n" +
                "	</div>\n" +
                "	<br class=\"clrfix\" />\n" +
                "</div>\n"
               );
            return Html.ToString();
        }

        [AjaxPro.AjaxMethod]
        public string RenderNewProductsByMenu(string siteid, string catid)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                //    "<div class=\"nproduct\" >\n" +
                //    "	<h3 class=\"title\">SẢN PHẨM MỚI</h3>\n" +
                //    "	<div class=\"morecat\">\n" +
                //    "		<ul>\n");
                //DataTable dtMenuNewPro = Menu_GetMenuNewProducts();
                //if (dtMenuNewPro.Rows.Count > 0)
                //{
                //    string cssAllcat = string.Empty;
                //    string Target = string.Empty;
                //    for (int i = 0; i < dtMenuNewPro.Rows.Count; i++)
                //    {
                //        if (dtMenuNewPro.Rows[i]["Target"] != null && Convert.ToInt32(dtMenuNewPro.Rows[i]["Target"]) == 1)
                //            Target = "target=\"_blank\"";
                //        else
                //            Target = string.Empty;
                //        if (dtMenuNewPro.Rows[i]["Title"].ToString().ToLower().Equals("xem toàn bộ"))
                //            cssAllcat = "class=\"allcat\"";//<li class=\"allcat\"><a href=\"#\">Xem toàn bộ</a></li>\n"+
                //        Html.Append(
                //    "			<li " + cssAllcat + "><a href=\"" + EnvInfo.HttpRoot + dtMenuNewPro.Rows[i]["Url"].ToString() + "\" " + Target + " onclick=\"" + dtMenuNewPro.Rows[i]["Description"].ToString().Trim() + "\">" + dtMenuNewPro.Rows[i]["Title"].ToString() + "</a></li>\n"
                //            );
                //    }
                //}
                //Html.Append(
                //    "		</ul>\n" +
                //    "	</div>\n" +
                //"	<div class=\"productwrapper\" \" id=\"divNewProducts>\n" +
                "		<table class=\"productlist\">\n");
            DataTable dtproduct = BuildProducts_NewReading(catid);
            if (dtproduct.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                for (int i = 0; i < dtproduct.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(dtproduct.Rows[i]["Image"].ToString()))
                        ImageName = dtproduct.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    if ((bool)dtproduct.Rows[i]["Status"])
                        Status = "Còn hàng";
                    else
                        Status = "Hết hàng";
                    float NewPriceProduct = Convert.ToInt64(dtproduct.Rows[i]["NewPrice"]);
                    ProductUrl = Screen.BuildUrlForProductDetails(dtproduct.Rows[i]["ProductID"].ToString(), dtproduct.Rows[i]["ProductName"].ToString(),
                                  dtproduct.Rows[i]["CateID"].ToString(), siteid);
                    if (i % 4 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "					<td>\n" +
                    "						<a class=\"thumb\" href=\"" + ProductUrl + "\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                    "						<div class=\"basicinfo\">\n" +
                    "							<h3><a href=\"" + ProductUrl + "\">" + dtproduct.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "							<ul>\n" +
                    "								<li><span class=\"caption\">Loại SP</span>: " + dtproduct.Rows[i]["Title"].ToString() + "</li>\n" +
                    "								<li><span class=\"caption\">Tình trạng</span>: " + Status + "</li>\n" +
                    "								<li><span class=\"caption\">Giá bán:</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "							</ul>\n" +
                    "						</div>\n" +
                    "						<div class=\"toolpro\">\n" +
                    "							<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dtproduct.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "						</div>\n" +
                    "					</td>\n"
                        );
                    if (i % 4 == 3)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dtproduct.Rows.Count % 4 != 3)
                    Html.Append(
                    "				</tr>\n");
            }
            else
            {
                Html.Append("<tr><td>Hiện chưa có sản phẩm nào thuộc nhóm này</td></tr>\n");
            }
            Html.Append(
                "			</table>\n" +
                "	</div>\n" +
                "	<br class=\"clrfix\" />\n"
                //"</div>\n"
               );
            return Html.ToString();
        }

        public string RenderSearchProduct(string keyword, string sortby, string strDataAlias,
            int ItemsPerRow,
            int NoOfVisiblePage,
            int CurrentPage,
            string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divSearchProductContent\" >\n" +
                BuildSearchProductContent(keyword, sortby, strDataAlias, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID) +
                "</div>\n"
                );
            return Html.ToString();
        }
        [AjaxPro.AjaxMethod]
        public string BuildSearchProductContent(string Keyword, string SortCondition, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = Products_Search(Keyword, SortCondition);
            string PagingText = new Paging().GetPagingSearch(Keyword, SortCondition, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID, ref StartIndex, ref EndIndex);
            Html.Append(
            "<h2 class=\"heading\">Tìm thấy [" + dt.Rows.Count.ToString() + "] sản phẩm\n");
            if (dt.Rows.Count > 0)
                Html.Append(RenderSortIndex("IndexOfSearchProduct", Keyword, SortCondition, strDataAlias, 16, 10, 0, JumpJavaScript, SiteID));
            Html.Append(
            "	<br class=\"clrfix\" />\n" +
            "</h2>\n" +
            "	<div class=\"productwrapper\">\n" +
            "		<table class=\"productlist\">\n");
            if (dt.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string CateID = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    if (dt.Rows[i]["Image"] != null)
                        ImageName = dt.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    if ((bool)dt.Rows[i]["Status"])
                        Status = "Còn hàng";
                    else
                        Status = "Hết hàng";
                    float NewPriceProduct = Convert.ToInt64(dt.Rows[i]["NewPrice"]);
                    try
                    {
                        CateID = Products_GetCateIDByProductID(dt.Rows[i]["ProductID"].ToString());
                    }
                    catch { }
                    ProductUrl = Screen.BuildUrlForProductDetails(dt.Rows[i]["ProductID"].ToString(), dt.Rows[i]["ProductName"].ToString(), CateID, SiteID);
                    if (i % 4 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "					<td>\n" +
                    "						<a class=\"thumb\" href=\"" + ProductUrl + "\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                    "						<div class=\"basicinfo\">\n" +
                    "							<h3><a href=\"" + ProductUrl + "\">" + dt.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "							<ul>\n" +
                    "								<li><span class=\"caption\">Loại SP</span>: " + dt.Rows[i]["Title"].ToString() + "</li>\n" +
                    "								<li><span class=\"caption\">Tình trạng</span>: " + Status + "</li>\n" +
                    "								<li><span class=\"caption\">Giá bán:</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "							</ul>\n" +
                    "						</div>\n" +
                    "						<div class=\"toolpro\">\n" +
                    "							<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dt.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "						</div>\n" +
                    "					</td>\n"
                        );
                    if (i % 4 == 3)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dt.Rows.Count % 4 != 3)
                    Html.Append(
                    "				</tr>\n");
            }

            Html.Append(
                "			</table>\n" +
                "	</div>\n"
               );
            if (PagingText.Trim().Length > 0)
            {
                Html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            return Html.ToString();
        }
        public string RenderSortIndex(string FunctionName, string Keyword, string SortValue, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append("");
            return Html.ToString();
            Html.Append(
                   "	<span class=\"sortproduct\">\n" +
                "			Sắp xếp: \n" +
                            "<select id=\"getsortproduct\" onchange=\"javascript:" + FunctionName + "('" + Keyword + "','" + strDataAlias + "','" + ItemsPerRow + "','" + NoOfVisiblePage + "','" + CurrentPage + "','" + JumpJavaScript + "','" + SiteID + "');\">\n" +
                            "	<option value=\"default\" " + GetDefaultSelect("default", SortValue) + ">Mặc định</option>\n" +
                            "	<option value=\"priceasc\" " + GetDefaultSelect("priceasc", SortValue) + ">Giá tăng dần</option>\n" +
                            "	<option value=\"pricedesc\" " + GetDefaultSelect("pricedesc", SortValue) + ">Giá giảm dần</option>\n" +
                            "	<option value=\"isseller\" " + GetDefaultSelect("isseller", SortValue) + ">Có khuyến mại</option>\n" +
                            "</select>\n" +
                "		</span>\n"
                );
            return Html.ToString();
        }
        public string GetDefaultSelect(string Value, string ValueCompare)
        {
            string RetValue = string.Empty;
            if (Value.Equals(ValueCompare))
                RetValue = "selected=\"selected\"";
            return RetValue;
        }
        #region News
        public string RenderNewsDetail(string siteid, int NewsId, int catid)
        {
            try
            {
                DataTable dtNewsRelation = new DataTable();
                DataTable dtNewsItem = News_GetItemByID(NewsId, catid, ref dtNewsRelation);
                if (dtNewsItem.Rows.Count == 0)
                    return "";

                int MaxNewsRelation = 5;
                StringBuilder Html = new StringBuilder();
                //-------------------
                Html.Append(
                "<div class=\"newsholder\"> \n" +
                "				<h1 class=\"title\">" + dtNewsItem.Rows[0]["Title"] + "</h1> \n" +
                "					<span class=\"datetime\"><em>Đăng ngày:</em> " + Convert.ToDateTime(dtNewsItem.Rows[0]["Created"]).ToString("dd/MM/yyyy") + "</span> \n" +
                "					<div class=\"desc\">" + dtNewsItem.Rows[0]["Description"] + "</div> \n" +
                "					<div class=\"bodynews\"> \n" + dtNewsItem.Rows[0]["Body"] +
                "					</div> \n" +
                "					<div class=\"othernews\"> \n" +
                "						<h3>Các tin khác</h3> \n" +
                "						<ul> \n");

                for (int iNews = 0; iNews < dtNewsRelation.Rows.Count; iNews++)
                {
                    string Subject = "";
                    if (dtNewsRelation.Rows[iNews]["Title"] != null)
                        Subject = dtNewsRelation.Rows[iNews]["Title"].ToString();

                    DateTime EntryDate = DateTime.Now;
                    if (dtNewsRelation.Rows[iNews]["Created"] != null)
                        EntryDate = (DateTime)dtNewsRelation.Rows[iNews]["Created"];

                    string Url = Screen.BuildUrlForNewsDetails(dtNewsRelation.Rows[iNews]["NewsID"].ToString(), dtNewsRelation.Rows[iNews]["Title"].ToString(), dtNewsRelation.Rows[iNews]["CateID"].ToString(), siteid);
                    Html.Append("<li><a href=\"" + Url + "\">" + Subject + " <span>" + EntryDate.ToString("dd/MM/yyyy") + "</span></a></li> \n");
                }
                Html.Append(
                    "						</ul> \n" +
                    "					</div> \n" +
                    "			</div> \n");
                //------------------

                return Html.ToString();
            }
            catch (Exception ex)
            {
                return "ERROR:Lỗi trong quá trình xử lý";
            }

        }
        public string RenderStaticNews(string siteid, int NewsID)
        {
            try
            {
                DataTable dt = StaticNews_ViewItemByID(NewsID);
                if (dt.Rows.Count == 0)
                    return "";
                StringBuilder Html = new StringBuilder();
                //-------------------
                Html.Append(
                "<div class=\"newsholder\"> \n" +
                "		<div class=\"bodynews\"> \n" + dt.Rows[0]["Body"] +
                "		</div> \n" +
                "</div> \n");
                //------------------

                return Html.ToString();
            }
            catch (Exception ex)
            {
                return "ERROR:Lỗi trong quá trình xử lý";
            }

        }

        #endregion


        public string RenderDetailProducts(string siteid, string pid)
        {
            StringBuilder Html = new StringBuilder();

            return Html.ToString();
        }
        public string RenderListBrand()
        {
            StringBuilder Html = new StringBuilder();
            Html.Append("<div class=\"endbottom\"></div>");
            Html.Append(
                "<div id=\"manufacture\" class=\"w960\">\n" +
                "	<a class=\"prev2\" href=\"javascript:avoid()\"></a>\n" +
                "	<a class=\"next2\" href=\"javascript:avoid()\"></a>\n" +
                "	<div class=\"slider2\">\n" +
                "		<ul>\n");
            DataTable dtBrand = Brands_Reading();
            if (dtBrand.Rows.Count > 0)
            {
                for (int i = 0; i < dtBrand.Rows.Count; i++)
                {
                    Html.Append(
                "			<li><a href=\"" + dtBrand.Rows[i]["Url"].ToString() + "\"><img src=\"" + EnvInfo.HttpRoot + "images/" + "logo/" + dtBrand.Rows[i]["Image"].ToString() + "\" /></a></li>\n");
                }
            }
            Html.Append(
                "		</ul>\n" +
                "	</div>\n" +
                "</div>\n"
                );
            return Html.ToString();
        }

        public string RenderFooter()
        {
            StringBuilder Html = new StringBuilder();
            Html.Append("<div class= \"endbottom\"></div>");
            return Html.ToString();
            //Html.Append(
            //    "<div id=\"branch\" class=\"w960\">\n"+
            //    "	<h2>COZY RESTAURANT</h2>\n");
            //try
            //{
            //    Html.Append(StatisNews_GetItemByTitle("Footer"));
            //}
            //catch { }
            //Html.Append(   
            //    "</div>\n" +
            //     "<div>\n"+
            //    "<input type=\"text\" name=\"system_input\" class=\"textsystembox\"  />\n" +
            //    "</div>\n"
            //    );
            //return Html.ToString();
        }

        public DataTable ReadingProductsByFilter(int catid)
        {
            string Query = "Select  DISTINCT p.ProductID, p.CateID, p.BrandID,p.Status, \n" +
"                         p.ProductName, p.Description,p.Body,p.Image,p.OtherImage,p.OldPrice,p.NewPrice, \n" +
"                        	   p.Created,p.Modified,p.CountView,p.BaoHanh,p.KhuyenMai,p.SPKhuyenMai \n" +
"  from tbl_Products P ,  \n" +
"	tbl_GroupFilters GF, dbo.tbl_Filter F   \n" +
"	where     \n" +
"    (P.NewPrice >=F.FromPrice) and   (P.NewPrice <=F.ToPrice)          \n" +
"    and F.GroupFilterID in (select GroupFilterID from tbl_GroupFilters    \n" +
"    where CateID = @catid) \n";

            SqlParameter[] arrParam ={
                    new SqlParameter("@catid", SqlDbType.Int)};
            arrParam[0].Value = catid;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }


        #region Product
        public DataTable ReadingFilter(int catid)
        {
            string Query = "select F.*, GF.GroupFilterName, (select COUNT(*) from tbl_Products P \n" +
                           "     where  \n" +
                           "     (CateID =@catid and P.NewPrice >=F.FromPrice and  \n" +
                           "     P.NewPrice <=F.ToPrice) or (CateID =@catid and P.Body like N'%'+ F.FilterName +'%' )) \n" +
                           "      as TotalProduct  \n" +
                           "      from  \n" +
                           "     tbl_GroupFilters GF, dbo.tbl_Filter F \n" +
                           " where \n" +
                           "     GF.CateID = @catid \n" +
                           "     and F.GroupFilterID in (select GroupFilterID from tbl_GroupFilters  \n" +
                           "     where CateID = @catid) \n" +
                           "    and F.GroupFilterID = GF.GroupFilterID \n" +
                           " order by GF.SortIndex, GF.GroupFilterName";
            SqlParameter[] arrParam ={
                    new SqlParameter("@catid", SqlDbType.Int)};
            arrParam[0].Value = catid;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public string RenderFilterProducts(string siteid, int catid)
        {
            StringBuilder Html = new StringBuilder();

            DataTable dtMenuTop = ReadingFilter(catid);

            Html.Append(
                //"<div id=\"rightcol\">\n"+
                "	<h4 class=\"heading\">"+MyResource.Filter.ToUpper()+"</h4>\n");
            bool inBoundGroup = true;
            string groupFilterName = string.Empty;

            for (int i = 0; i < dtMenuTop.Rows.Count; i++)
            {

                if (i == 0 || !inBoundGroup)
                {
                    groupFilterName = dtMenuTop.Rows[i]["GroupFilterName"].ToString();
                    Html.Append(
                        "	<div class=\"searchmodule\">\n" +
                        "		<h5 class=\"heading\"><span>" + groupFilterName + "</span></h5>\n" +
                        "		<div class=\"searchbody\">\n" +
                        "			<ul class=\"textlist\">\n" +
                        "				<li><a href=\"" + EnvInfo.HttpRoot + "productfitler.aspx?cid=" + catid + "" + "\">" + dtMenuTop.Rows[i]["FilterName"].ToString() + " <span>(" + dtMenuTop.Rows[i]["TotalProduct"].ToString() + ")</span></a></li>\n");
                    inBoundGroup = true;
                }
                else
                {
                    Html.Append(
                    "				<li><a href=\"" + EnvInfo.HttpRoot + "productfitler.aspx?cid=" + catid + "\">" + dtMenuTop.Rows[i]["FilterName"].ToString() + " <span>(" + dtMenuTop.Rows[i]["TotalProduct"].ToString() + ")</span></a></li>\n");
                }
                if (i < dtMenuTop.Rows.Count - 1)
                {
                    if (groupFilterName != dtMenuTop.Rows[i + 1]["GroupFilterName"].ToString())
                    {
                        inBoundGroup = false;
                        Html.Append(
                            "			</ul>\n" +
                            "		</div>\n" +
                            "	</div>\n");

                    }
                }
                else
                {
                    Html.Append(
                           "			</ul>\n" +
                           "		</div>\n" +
                           "	</div>\n");
                }


            }

            return Html.ToString();
        }
        public DataTable ReadingProductsById(string objid)
        {
            string Query = "select P.*,C.Title  from tbl_Products P left join tbl_Category C on P.CateID = C.CateID where P.ProductID=@id";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@id", SqlDbType.VarChar,36)};
            arrParam[0].Value = objid;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }
        public DataTable ReadingProductsByIdToCart(string objid, string itemNumber)
        {
            string Query = "select ProductID,ProductName, NewPrice, '" + itemNumber + "' as ItemNumber, CateID,[BaoHanh] from tbl_Products P where P.ProductID=@id";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@id", SqlDbType.VarChar,50)};
            arrParam[0].Value = objid;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            dtResult.PrimaryKey = new DataColumn[] { dtResult.Columns["ProductID"] };
            return dtResult;
        }
        public string GetProductStatus(string status)
        {
            string reval = string.Empty;
            if (status.Equals("0"))
                reval = MyResource.OutStock;
            else
                reval = MyResource.InStock;
            return reval;
        }
        #endregion
        public string BuildLeftMenu()
        {
            string UserName = SecurityServices.GetCurrentUser();
            if (string.IsNullOrEmpty(UserName))
                return "ERROR! can't get current username";
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div class=\"groupItem rawmodule\"> \n" +
                "                    <div class=\"urbangreymenu\"> \n" +
                "                    <script type=\"text/javascript\"> \n" +
                "                        ddaccordion.init({ \n" +
                "                            headerclass: \"headerbar\", //Shared CSS class name of headers group \n" +
                "                            contentclass: \"submenu\", //Shared CSS class name of contents group \n" +
                "                            revealtype: \"clickgo\", //Reveal content when user clicks or onmouseover the header? Valid value: click, clickgo, or mouseover \n" +
                "                            mouseoverdelay: 200, //if revealtype=\"mouseover\", set delay in milliseconds before header expands onMouseover \n" +
                "                            collapseprev: true, //Collapse previous content (so only one open at any time)? true/false \n" +
                "                            defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc] [] denotes no content \n" +
                "                            onemustopen: true, //Specify whether at least one header should be open always (so never all headers closed) \n" +
                "                            animatedefault: false, //Should contents open by default be animated into view? \n" +
                "                            persiststate: true, //persist state of opened contents within browser session? \n" +
                "                            toggleclass: [\"\", \"selected\"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively [class1, class2] \n" +
                "                            toggleHtml: [\"\", \"\", \"\"], //Additional Html added to the header when it's collapsed and expanded, respectively  [position, Html1, Html2] (see docs) \n" +
                "                            animatespeed: \"normal\", //speed of animation: integer in milliseconds (ie: 200), or keywords fast, normal, or slow \n" +
                "                            oninit:function(headers, expandedindices){ //custom code to run when headers have initalized \n" +
                "                                //do nothing \n" +
                "                            }, \n" +
                "                            onopenclose:function(header, index, state, isuseractivatedisuseractivated){ //custom code to run whenever a header is opened or closed \n" +
                "                                //do nothing \n" +
                "                            } \n" +
                "                        }) \n" +
                "                        </script><style type=\"text/css\"> \n" +
                "    .submenu{display: none} \n" +
                "    a.hiddenajaxlink{display: none} \n" +
                "    </style> \n" +
                "                        <div class=\"lmenu_top\"></div> \n");

            DataTable dtParent = LeftMenu_GetItemRootByUserName(UserName);
            if (dtParent.Rows.Count > 0)
            {
                for (int i = 0; i < dtParent.Rows.Count; i++)
                {
                    Html.Append("<h3  headerindex=\"" + i + "h\" class=\"headerbar\"><a href=\"" + dtParent.Rows[i]["Url"].ToString() + "\">" + dtParent.Rows[i]["Title"].ToString() + "</a></h3> \n");
                    DataTable dtChildOne = LeftMenu_GetItemByParentIDAndUserName(int.Parse("0" + dtParent.Rows[i]["MenuID"].ToString()), UserName);
                    if (dtChildOne.Rows.Count > 0)
                    {
                        for (int subIndex = 0; subIndex < dtChildOne.Rows.Count; subIndex++)
                        {
                            if (subIndex == 0)
                            {
                                Html.Append("<ul class=\"submenu\" contentindex=\"" + i + "c\"  ");
                                if (i == 0)
                                    Html.Append("style=\"display: block;\">\n");
                                else
                                    Html.Append("style=\"display: none;\">\n");
                            }
                            Html.Append("<li  ");
                            DataTable dtChildTwo = LeftMenu_GetItemByParentIDAndUserName(int.Parse("0" + dtChildOne.Rows[subIndex]["MenuID"].ToString()), UserName);
                            if (dtChildTwo.Rows.Count > 0)
                                Html.Append("class=\"haschild\"");
                            Html.Append("><a href=\"" + dtChildOne.Rows[subIndex]["Url"].ToString() + "\">" + dtChildOne.Rows[subIndex]["Title"].ToString() + "</a> \n");

                            for (int isubIndex = 0; isubIndex < dtChildTwo.Rows.Count; isubIndex++)
                            {
                                if (isubIndex == 0)
                                    Html.Append("<ul class=\"submenu1\">\n");

                                Html.Append("<li><a href=\"" + dtChildTwo.Rows[isubIndex]["Url"].ToString() + "\">" + dtChildTwo.Rows[isubIndex]["Title"].ToString() + "</a> \n");
                                DataTable dtChildThree = LeftMenu_GetItemByParentIDAndUserName(int.Parse("0" + dtChildTwo.Rows[isubIndex]["MenuID"].ToString()), UserName);
                                if (dtChildThree.Rows.Count > 0)
                                {
                                    for (int isub3Index = 0; isub3Index < dtChildThree.Rows.Count; isub3Index++)
                                    {
                                        if (isub3Index == 0)
                                            Html.Append("<ul class=\"submenu2\"> \n");

                                        Html.Append("<li><a href=\"" + dtChildThree.Rows[isub3Index]["Url"].ToString() + "\">" + dtChildThree.Rows[isub3Index]["Title"].ToString() + "</a></li> \n");

                                        if (isub3Index == dtChildThree.Rows.Count - 1)
                                            Html.Append("</ul> \n");
                                    }
                                }
                                Html.Append("</li> \n");
                                if (isubIndex == dtChildTwo.Rows.Count - 1)
                                    Html.Append("</ul> \n");

                            }

                            Html.Append("</li> \n");
                            if (subIndex == dtChildOne.Rows.Count - 1)
                                Html.Append("</ul> \n");

                        }
                    }

                }
            }
            else
            {
                Html.Append("<span><img src=\"" + EnvInfo.HttpRoot + "images/icons/icon_warning.png\" border=\"0px\" /> deny access.</span> \n");
            }
            Html.Append(
            "                        <div class=\"lmenu_bottom\"></div> \n" +
            "                    </div> \n" +
            "                </div>"
            );

            return Html.ToString();
        }
        //new render new filter
        public string RenderViewFilter(int CateID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<a href=\"javascript:ddtreemenu.flatten('treemenu1', 'expand')\">Mở tất cả</a> | \n" +
                "<a href=\"javascript:ddtreemenu.flatten('treemenu1', 'contact')\">Đóng tất cả</a>\n" +
                "<ul id=\"treemenu1\" class=\"treeview\">\n" +
                "<li>" + Category_GetTitle(CateID) + "\n");
            DataTable dtGroupFilter = GroupFilters_ViewItemByCateID(CateID);
            if (dtGroupFilter.Rows.Count > 0)
            {
                for (int i = 0; i < dtGroupFilter.Rows.Count; i++)
                {
                    if (i == 0)
                        Html.Append(
                        "	<ul>\n");
                    Html.Append(
                        "	<li><a href=\"../administrator/edititem.aspx?edit=e_filter&itemid=" + CateID + "&groupfilter=" + dtGroupFilter.Rows[i]["GroupFilterID"] + "\">" + dtGroupFilter.Rows[i]["GroupFilterName"].ToString() + "(" + dtGroupFilter.Rows[i]["SortIndex"].ToString() + ")</a>\n"
                            );
                    DataTable dtFilter = Filter_ViewItemFilterByGroupFilterID(int.Parse("0" + dtGroupFilter.Rows[i]["GroupFilterID"]));
                    if (dtFilter.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtFilter.Rows.Count; j++)
                        {
                            if (j == 0)
                                Html.Append(
                        "		<ul>\n");
                            Html.Append(
                        "		<li><a href=\"../administrator/edititem.aspx?edit=e_filter&itemid=" + CateID + "&groupfilter=" + dtGroupFilter.Rows[i]["GroupFilterID"] + "&filter=" + dtFilter.Rows[j]["FilterID"] + "\">" + dtFilter.Rows[j]["FilterName"].ToString() + "(" + dtFilter.Rows[j]["SortIndex"].ToString() + ")</a></li>\n"
                                );
                            if (j == dtFilter.Rows.Count - 1)
                                Html.Append(
                        "		</ul>\n");
                        }
                    }
                    if (i == dtGroupFilter.Rows.Count - 1)
                        Html.Append(
                        "   </li>\n" +
                        "   </ul>\n"
                            );
                }
            }
            Html.Append(
                "</li>\n" +
                "</ul>\n" +
                "<script type=\"text/javascript\">\n" +
                "    ddtreemenu.createTree(\"treemenu1\", true)\n" +
                "</script>\n"
                );
            return Html.ToString();
        }
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string RenderMoreProductDetail(string pid, string cid, string strDataAlias,
            int ItemsPerRow,
            int NoOfVisiblePage,
            int CurrentPage,
            string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"pro_content_box\">\n" +
                "<div id=\"tabMenudetail\">\n" +
                "	<div>\n" +
                "		<span class=\"clear\"></span>\n" +
                "		<ul>\n" +
                "			<li class=\"curent\" id=\"tab_desc\"><a onclick=\"switchProTab('desc')\" href=\"javascript:;\"><span>" + MyResource.MoreInfomation + "&nbsp;&nbsp;</span></a></li>			\n" +
                "			<li id=\"tab_sameproduct\"><a onclick=\"switchProTab('sameproduct')\" href=\"javascript:;\"><span>Sản phẩm cùng loại&nbsp;&nbsp;</span></a></li>			\n" +
                "			<li id=\"tab_review\"><a onclick=\"switchProTab('review')\" href=\"javascript:;\"><span>Đánh giá&nbsp;&nbsp;</span></a></li>\n" +
                "		</ul>\n" +
                "		<span class=\"clear\"></span>\n" +
                "	</div>\n" +
                "</div>\n" +
                "<div class=\"clear\"></div>\n" +
                "<input type=\"hidden\" value=\"desc\" id=\"current_tap\" />\n" +
                "<div id=\"pro_content_desc\" style=\"display: block;\">\n" +
                Products_GetBody(pid) +
                "</div>\n" +
                "<div id=\"pro_content_sameproduct\" style=\"display: none;\">\n" +
                "   <div id=\"divSameProductContent\">\n" +
                BuildSameProductContent(pid, cid, strDataAlias, 4, 10, CurrentPage, JumpJavaScript, SiteID) +
                "   </div>\n" +
                "	<div class=\"clear\"></div>\n" +
                "</div>\n" +
                "<div id=\"pro_content_review\" style=\"display: none;\">\n" +
                "    <div id=\"divCommentByProductIDContent\"> \n" +
                BuildCommentsByProductIDContent(pid, strDataAlias, ItemsPerRow, NoOfVisiblePage, CurrentPage, "ClientJumpPagesComment") +
                "    </div> \n" +
                "<div class=\"clear\"></div>\n" +
                "	<div><a onclick=\"javascript:loadReviewForm();\" href=\"javascript:void(0);\" title=\"Ý kiến của bạn\"><img src=\"" + EnvInfo.HttpRoot + "images/icons/Y-kien-cua-ban.gif\" border=\"0px\" /></a></div>\n" +
                "	<div id=\"formcommentproduct\" style=\"display: none;\">\n" +
                "		<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">			\n" +
                "		<tbody>	\n" +
                "			<tr>    \n" +
                "				<td class=\"next-current-navigation\">Gửi thảo luận:</td>\n" +
                "			</tr>\n" +
                "			<tr>    \n" +
                "				<td style=\"border-top:#fff 1px solid;\"><img alt=\"\" src=\"" + EnvInfo.HttpRoot + "images/icons/pixel_1_1.gif\" width=\"1\" height=\"3\"></td>\n" +
                "			</tr>\n" +
                "			<tr> \n" +
                "			  <td style=\"font-weight:bold;text-align:left;color:#404040;\">Họ và tên: <input id=\"txtFullName\" name=\"txtFullName\" type=\"text\" style=\"font-size:12px;width:150px;text-align:left;color:#404040;background: #fff url(" + EnvInfo.HttpRoot + "images/global/eform-bg.gif) repeat-x top;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border: #cccccc 1px solid;padding:4px;padding-left:10px;padding-right:10px;\" tabindex=\"10\" />&nbsp;&nbsp;&nbsp;&nbsp;Địa chỉ email: <input id=\"txtEmail\" name=\"txtEmail\" type=\"text\" style=\"font-size:12px;width:200px;text-align:left;color:#404040;background: #fff url(" + EnvInfo.HttpRoot + "images/global/eform-bg.gif) repeat-x top;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border: #cccccc 1px solid;padding:4px;padding-left:10px;padding-right:10px;\" tabindex=\"11\" /></td>\n" +
                "			</tr>\n" +
                "			<tr> \n" +
                "			  <td style=\"padding-bottom:5px;\"><textarea name=\"txtBody\" cols=\"60\" rows=\"8\" id=\"txtBody\" style=\"font-size:12px; width:97%; text-align:left; color:#404040;background: #fff url(" + EnvInfo.HttpRoot + "images/global/eform-bg.gif) repeat-x top;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border: #cccccc 1px solid;padding:2px;padding-left:10px;padding-right:10px;\" tabindex=\"12\"></textarea></td>\n" +
                "			</tr>\n" +
                "			<tr> \n" +
                "			  <td>" +
                "               <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                "				<tbody>" +
                "                 <tr>\n" +
                "					<td style=\"font-weight:bold;text-align:left;color:#404040;\">Mã kiểm tra:&nbsp;" + new CommonBLL().RandomNumber() + "&nbsp;<input type=\"hidden\" value=\"" + CommonBLL.TotalCode + "\" id=\"hdtotalcode\" /><input id=\"txtCode\" name=\"txtCode\" type=\"text\" style=\"font-size:12px;width:60px;text-align:left;color:#404040;background: #fff url(" + EnvInfo.HttpRoot + "images/global/eform-bg.gif) repeat-x top;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border: #cccccc 1px solid;padding:4px;padding-left:10px;padding-right:10px;\" tabindex=\"13\" value=\"\" /></td>\n" +
                "					<td style=\"text-align:right;\"><input tabindex=\"14\" type=\"button\" name=\"button\" class=\"button medium blue ui-widget\" onclick=\"javascript:clickSubmitComment('" + pid + "');\" value=\"  Gửi thảo luận  \"/><input tabindex=\"15\" type=\"button\" name=\"button\" class=\"button medium blue ui-widget\" onclick=\"javascript:closeReviewForm();\" value=\"Đóng lại\"/></td>\n" +
                "				  </tr>\n" +
                "				</tbody>" +
                "               </table>" +
                "             </td>\n" +
                "			</tr>\n" +
                "		</tbody>		  \n" +
                "		</table>\n" +
                "	</div>\n" +
                //" alert('Full path: ' + window.location.href);\n "+
                //string url = HttpContext.Current.Request.Url.AbsoluteUri;
                //http://localhost:1302/TESTERS/Default6.aspx
                "<div class=\"fb-comments\" data-href=\"http://vnexpress.net/tin-tuc/thoi-su/can-ton-vinh-the-he-da-hy-sinh-trong-chien-tranh-bien-gioi-1979-2952222.html\" data-numposts=\"10\" data-colorscheme=\"light\"></div>\n" +

                "</div>\n" +
                "</div>\n"
                );
            return Html.ToString();
        }
        [AjaxPro.AjaxMethod]
        public string BuildCommentsByProductIDContent(string ProductID, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript)
        {
            StringBuilder html = new StringBuilder();
            html.Append(
                "	<div  id=\"viewdetailcomment\">\n" +
                "		<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">		\n" +
                "		<tbody>\n" +
                "			<tr>    \n" +
                "				<td class=\"next-current-navigation\">Thảo luận về sản phẩm này:</td>\n" +
                "			</tr>\n" +
                "			<tr>    \n" +
                "				<td style=\"border-top:#fff 1px solid;\"><img alt=\"\" src=\"/images/icons/pixel_1_1.gif\" width=\"1\" height=\"3\"></td>\n" +
                "			</tr>\n");
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = CommentProduct_GetList(ProductID);
            string PagingText = new Paging().GetPaging(ProductID, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, ref StartIndex, ref EndIndex);
            if (dt.Rows.Count > 0)
            {
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    string FullName = dt.Rows[i]["FullName"].ToString();
                    string Email = dt.Rows[i]["Email"].ToString();
                    string Title = dt.Rows[i]["Title"].ToString();
                    string Body = dt.Rows[i]["Body"].ToString();
                    string Modified = Convert.ToDateTime(dt.Rows[i]["Modified"]).ToString("dd/MM/yyy HH:mm:ss");

                    html.Append(
                            "			<tr>    \n" +
                            "				<td class=\"comment-by\" style=\"padding-top:5px;\">" + FullName + "&nbsp;viết:</td>\n" +
                            "			</tr>\n" +
                            "			<tr>    \n" +
                            "				<td class=\"comment-detail\" style=\"padding-top:5px;\">" + Body + "</td>\n" +
                            "			</tr>\n" +
                            "			<tr>    \n" +
                            "				<td class=\"comment-date\" style=\"padding-top:5px;\">Cập nhật: " + Modified + "</td>\n" +
                            "			</tr>\n");
                }
            }
            else
            {
                html.Append(
                "			<tr>    \n" +
                "				<td><span class=\"clsnorowscomment\">Chưa có thảo luận gì về sản phẩm này!</span></td>\n" +
                "			</tr>\n");
            }
            html.Append(
                "		</tbody>\n" +
                "		</table>\n" +
                "	</div>\n"
                );
            if (PagingText.Trim().Length > 0)
            {
                html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            return html.ToString();
        }
        [AjaxPro.AjaxMethod]
        public string BuildSameProductContent(string ProductID, string CateID, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "	<div class=\"productwrapper\">\n" +
                "		<table class=\"productlist\">\n");
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = Products_ListSPCungLoai(ProductID, int.Parse("0" + CateID));
            string PagingText = new Paging().GetPaging(ProductID, CateID, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, ref StartIndex, ref EndIndex);
            if (dt.Rows.Count > 0)
            {
                string ProductUrl = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string ProductName = string.Empty;
                string OldPriceProduct = string.Empty;
                string ImageName = string.Empty;
                string Status = string.Empty;
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    if (!string.IsNullOrEmpty(dt.Rows[i]["Image"].ToString()))
                        ImageName = dt.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    if ((bool)dt.Rows[i]["Status"])
                        Status = "Còn hàng";
                    else
                        Status = "Hết hàng";
                    float NewPriceProduct = Convert.ToInt64(dt.Rows[i]["NewPrice"]);
                    ProductUrl = Screen.BuildUrlForProductDetails(dt.Rows[i]["ProductID"].ToString(), dt.Rows[i]["ProductName"].ToString(),
                                  dt.Rows[i]["CateID"].ToString(), SiteID);
                    if (i % 4 == 0)
                        Html.Append(
                   "				<tr>\n"
                   );
                    Html.Append(
                    "					<td>\n" +
                    "						<a class=\"thumb\" href=\"" + ProductUrl + "\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                    "						<div class=\"basicinfo\">\n" +
                    "							<h3><a href=\"" + ProductUrl + "\">" + dt.Rows[i]["ProductName"].ToString() + "</a></h3>\n" +
                    "							<ul>\n" +
                    "								<li><span class=\"caption\">Loại SP</span>: " + dt.Rows[i]["Title"].ToString() + "</li>\n" +
                    "								<li><span class=\"caption\">Tình trạng</span>: " + Status + "</li>\n" +
                    "								<li><span class=\"caption\">Giá bán:</span> <span class=\"price\">" + NewPriceProduct.ToString("#,###") + "</span></li>\n" +
                    "							</ul>\n" +
                    "						</div>\n" +
                    "						<div class=\"toolpro\">\n" +
                    "							<a href=\"javascript:void(0);\" onclick=\"javascript:addToShoppingCart('" + EnvInfo.HttpRoot + "','" + dt.Rows[i]["ProductID"] + "');\" class=\"addtocart\">" + MyResource.AddToCart + "</a>\n" +
                    "						</div>\n" +
                    "					</td>\n"
                        );
                    if (i % 4 == 3)
                        Html.Append(
                   "				</tr>\n");
                }
                if (dt.Rows.Count % 4 != 3)
                    Html.Append(
                    "				</tr>\n");
            }
            Html.Append(
                "			</table>\n" +
                "	</div>\n"
               );
            if (PagingText.Trim().Length > 0)
            {
                Html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            return Html.ToString();
        }
        public string RenderNewsByCat(int gid, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            string GroupTitle = string.Empty;
            try
            {
                GroupTitle = GroupNews_GetTitle(gid);
            }
            catch { }
            Html.Append(
                "<div class=\"groupItem tabmodule\">\n" +
                "	<div class=\"itemHeader\"><h3><span class=\"title\">" + GroupTitle + "</span><span class=\"right\"></span></h3></div>\n" +
                "	<div class=\"itemContent\">							\n" +
                "   <div id=\"divnewsbycatcontent\">\n" +
                BuildNewsByCatContent(gid.ToString(), strDataAlias, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID) +
                "   </div>\n" +
                "	<div class=\"clrfix\"></div>\n" +
                "	</div>\n" +
                "</div>\n"
                );
            return Html.ToString();
        }
        [AjaxPro.AjaxMethod]
        public string BuildNewsByCatContent(string CateID, string strDataAlias, int ItemsPerRow, int NoOfVisiblePage, int CurrentPage, string JumpJavaScript, string SiteID)
        {
            StringBuilder Html = new StringBuilder();
            int StartIndex = 0;
            int EndIndex = 0;
            DataTable dt = News_GetItemByCateID(int.Parse("0" + CateID));
            string PagingText = new Paging().GetPagingNewsByCat(CateID, strDataAlias, dt.Rows.Count, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript, SiteID, ref StartIndex, ref EndIndex);
            if (dt.Rows.Count > 0)
            {
                string NewsUrl = string.Empty;
                string Title = string.Empty;
                string Description = string.Empty;
                string PublishDate = string.Empty;
                string ImageName = string.Empty;
                for (int i = StartIndex; i < EndIndex; i++)
                {
                    if (!string.IsNullOrEmpty(dt.Rows[i]["Image"].ToString()))
                        ImageName = dt.Rows[i]["Image"].ToString();
                    else
                        ImageName = "no_image.jpg";
                    Title = dt.Rows[i]["Title"].ToString();
                    Description = dt.Rows[i]["Description"].ToString();
                    PublishDate = Convert.ToDateTime(dt.Rows[i]["Created"]).ToString("dd/MM/yyy");
                    NewsUrl = Screen.BuildUrlForNewsDetails(dt.Rows[i]["NewsID"].ToString(), dt.Rows[i]["Title"].ToString(),
                                  dt.Rows[i]["CateID"].ToString(), SiteID);
                    Html.Append(
                        "		<div class=\"newslist\">\n" +
                        "			<a href=\"" + NewsUrl + "\" class=\"thumb\"><img src=\"" + EnvInfo.HttpRoot + "smallimages/" + ImageName + "\" /></a>\n" +
                        "			<a href=\"" + NewsUrl + "\" class=\"listtitle\">" + Title + " <span>(" + PublishDate + ")</span></a><br />\n" +
                        "			<span class=\"shortdesc2\">\n" +
                        "				" + Description + "\n" +
                        "			</span>\n" +
                        "		</div>		\n" +
                        "		<div class=\"splitter\"></div>		\n"
                        );
                }
            }
            if (PagingText.Trim().Length > 0)
            {
                Html.Append("<div class=\"phantrang\">\n" + PagingText +
                            "	<div class=\"clrfix\"></div>\n" +
                            "</div> \n");
            }
            return Html.ToString();
        }

        public DataTable GetOrderDetail(string ItemID)
        {
            //string Query = "Select Id, Title, Body, Created, Sender, Email, Phone From tbl_CartOrder " +
            //            "	Where Id=@ItemID ";
            string Query = //"Select Id, Title, Body, Created, Sender, Email, Phone  From tbl_CartOrder " +
             "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
             "SELECT TOP 1000 	 \n" +
             " o.OrderID, \n" +
                "SUBSTRING(CONVERT(varchar(36),o.OrderID),1,8) as ID \n" +
             "     , d.ProductID \n" +
             "     ,d.ProductName \n" +
             "     ,d.Price \n" +
             "     ,d.Quantity \n" +
             "     ,d.TotalMoney      \n" +
             "     ,s.StatusName \n" +
             "     ,s.StatusId \n" +
             "      \n" +
             " FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_OrderDetail d,tbl_StatusOrder s \n" +
             " where o.OrderID = d.OrderID and o.StatusOrderID = s.StatusID \n" + 
                         "  and o.OrderID =@ItemID ";

            SqlParameter[] arrParam ={
                    new SqlParameter("@ItemID", SqlDbType.VarChar)};
            arrParam[0].Value = ItemID;
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }

        public DataTable GetOrderStatus()
        {
            
            string Query =
             "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
            "SELECT [StatusID] \n" +
            "      ,[StatusName] \n" +
            "      ,[SortIndex] \n" +
            "  FROM [DBShoppingCart_New].[dbo].[tbl_StatusOrder] \n";
            
            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }

        public DataTable CartOrder_GetList(int statusId, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By Created desc ";
            string Query = //"Select Id, Title, Body, Created, Sender, Email, Phone  From tbl_CartOrder " +
                "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
                "SELECT \n" +
                " o.OrderId, " +
                " SUBSTRING(CONVERT(varchar(36),[OrderID]),1,8)     as ID     " +
                "      ,o.[CustommerID]                   \n" +
                "      ,o.[Created], \n" +
                "      c.FullName, \n" +
                "   c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName \n" +
                "       \n" +
                "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s \n" +
                "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID \n" +
                "  and o.StatusOrderID = @StatusOrderID " +
                        OrderBy;

            SqlParameter[] arrParam ={
                    new SqlParameter("@StatusOrderID", SqlDbType.SmallInt)};
            arrParam[0].Value = statusId;

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query,arrParam);
            return dtResult;
        }

        public DataTable Report_CartOrderGetList(int statusId, string FromDate, string ToDate)
        {
            //string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            //if (!string.IsNullOrEmpty(OrderBy))
            //    OrderBy = " Order By " + OrderBy;
            //else
            string OrderBy = "   Order By Created desc ";
            string Query = //"Select Id, Title, Body, Created, Sender, Email, Phone  From tbl_CartOrder " +
                "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
                "SELECT \n" +
                " o.OrderId, " +
                " SUBSTRING(CONVERT(varchar(36),o.OrderID),1,8)     as ID     " +
                "      ,o.[CustommerID]                   \n" +
                "      ,o.[Created], \n" +
                "      c.FullName, \n" +
                "      c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName ,\n" +
                "  SUM(d.TotalMoney)  as Total  " +
                "       \n" +
                "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s , tbl_OrderDetail d \n" +
                "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID \n" +
                "  and o.StatusOrderID = @StatusOrderID " +
                "  and d.OrderID = o.OrderID ";

            if (!string.IsNullOrEmpty(FromDate))
                Query += " And convert(datetime,o.Created,103) BETWEEN convert(datetime,'" + FromDate + "',103) ";
                if (!string.IsNullOrEmpty(ToDate))
                    Query += " And dateadd(dd,1,convert(datetime,'" + ToDate + "',103) " +
                        " )";

                Query +=
                    "      group by " +
                    "      o.OrderId " +
                    "      ,o.[CustommerID] \n" +
                    "      ,o.[Created], \n" +
                    "      c.FullName, \n" +
                    "      c.Email,    \n" +
                    "      c.PhoneNumber, \n" +
                    "      c.Address, \n" +
                    "      s.StatusName \n";

                Query += OrderBy;

            SqlParameter[] arrParam ={
                    new SqlParameter("@StatusOrderID", SqlDbType.SmallInt)};
            arrParam[0].Value = statusId;

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);
            return dtResult;
        }


        public DataTable CartOrder_GetList(string  CustomerId, string SortExpression, string SortDirection)
        {
            string OrderBy = CommonBLL.GetValueSortOrder("", SortExpression, SortDirection);
            if (!string.IsNullOrEmpty(OrderBy))
                OrderBy = " Order By " + OrderBy;
            else
                OrderBy = "   Order By Created desc ";
            string Query = //"Select Id, Title, Body, Created, Sender, Email, Phone  From tbl_CartOrder " +
                "/****** Script for SelectTopNRows command from SSMS  ******/ \n" +
                "SELECT \n" +
                " o.OrderId, " +
                " SUBSTRING(CONVERT(varchar(36),o.OrderId),1,8)     as ID     " +
                "      ,o.[CustommerID]                   \n" +
                "      ,o.[Created], \n" +
                "      c.FullName \n" +

                "      ,d.[ProductName]                   \n" +
                "      ,d.[Quantity], \n" +
                "      d.Price, \n" +
                "      d.TotalMoney, \n" +

                "   c.Email,    \n" +
                "      c.PhoneNumber, \n" +
                "      c.Address, \n" +
                "      s.StatusName \n" +


                "       \n" +
                "  FROM [DBShoppingCart_New].[dbo].[tbl_Order] o ,tbl_Custommers c,tbl_StatusOrder s, tbl_OrderDetail d \n" +
                "  where o.CustommerID = c.CustommerID and o.StatusOrderID = s.StatusID \n" +
                "  and d.OrderID= o.OrderID " +
                "  and o.CustommerID= @CustommerID " +
                        OrderBy;

            SqlParameter[] arrParam ={
                    new SqlParameter("@CustommerID", SqlDbType.VarChar,36)};
            arrParam[0].Value = CustomerId;

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableParam(Query, arrParam);

            return dtResult;
        }


        public void UpdateCountView(string ProductID)
        {
            string Query = " Update tbl_Products set CountView = CountView + 1  where ProductID = @ProductID ";
            SqlParameter[] arrParam ={                  
                    new SqlParameter("@ProductID", SqlDbType.VarChar,36)};
                                     //new SqlParameter("@CountView", SqlDbType.Int)};
            
            arrParam[0].Value = ProductID;
            //arrParam[1].Value = CountView;

            DataTable dtResult = new DataTable();
            DB.ExeCuteSqlParam(Query, arrParam);            
        }

        public string Reports_ProductRender(bool mostView, DataTable dtproducts,string columName)
        {
            string Header = "Product most view";            
            if (!mostView) {

                Header = "Product most buy";
            }
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divcartholder\" class=\"contactholder\">\n" +
                "	<h1 class=\"title\">" + Header + "</h1>\n" +
                "	<span class=\"legend\">\n" +
                "	</span>\n" +
                "	<div class=\"contactform\">\n" +
                "											\n" +
                "		<table id=\"dtcart\" class=\"carttable\" border>\n" +
                 "			<tr>\n" +
                "				<th class=\"stt\">" + MyResource.Index + "</th>\n" +
                "				<th class=\"stt\">ID</th>\n" +
                "				<th class=\"name\">" + MyResource.ProductName + "</th>\n" +
                "				<th class=\"price\">" + MyResource.ProductPrice + " (vnđ)</th>\n" +
                "				<th class=\"sl\">" + MyResource.ProductType + "</th>\n" +
                "				<th class=\"total\">" + columName + "</th>\n" +                
                "			</tr>\n"
                );            
            double price = 0;            
            string productCode = string.Empty;
            
            for (int i = 0; i < dtproducts.Rows.Count; i++)
            {
                productCode = dtproducts.Rows[i]["ProductID"].ToString();                              
                price = Convert.ToDouble(dtproducts.Rows[i]["NewPrice"]);
                Html.Append(

                "			<tr class=\"odd\">\n" +
                "				<td class=\"stt\">" + (i + 1) + "</td>\n" +
                "				<td class=\"stt\">" + productCode + "</td>\n" +
                "				<td class=\"name\">"+ dtproducts.Rows[i]["ProductName"] + "</td>\n" +
                "				<td class=\"price\">" + price.ToString("#,###") + "</td>\n" +
                "				<td class=\"sl\">" + dtproducts.Rows[i]["Title"] + "</td>\n" +
                "				<td class=\"total\">" + dtproducts.Rows[i][columName] + "</td>\n" +              
                "			</tr>\n");                
            }            
            Html.Append(             
                "</table>" +
                "	</div>\n" +
                "</div>\n");            
            return Html.ToString();
        }

        public DataTable GetProductsByMostView()
        {
            string Query =
            "select P.*,C.Title  from tbl_Products P left join tbl_Category C on P.CateID = C.CateID order by CountView desc";

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }


        //public DataTable GetProductsByMostView(bool mostView,string frDate, string toDate)
        //{
        //    string Query =
        //    "select P.*,C.Title  from tbl_Products P, tbl_Category C where P.CateID = C.CateID ";

        //    if (mostView)
        //    {
        //        Query += " order by CountView desc ";
        //    }
        //    else
        //    {

        //        if (!string.IsNullOrEmpty(frDate))
        //            Query += " And convert(datetime,o.Created,103) BETWEEN convert(datetime,'" + frDate + "',103) ";
        //        if (!string.IsNullOrEmpty(toDate))
        //            Query += " And dateadd(dd,1,convert(datetime,'" + toDate + "',103) ";                        
        //        Query += " order by CountView asc ";
        //    }

        //    DataTable dtResult = new DataTable();
        //    dtResult = DB.ViewTableSql(Query);
        //    return dtResult;
        //}

        public DataTable GetProductsByMostBuy(bool mostView, string frDate, string toDate)
        {
            string Query = "SELECT d.ProductID,p.ProductName,p.NewPrice,c.Title ,  COUNT(d.ProductID) as Buy \n" +
            "       \n" +
            "  from tbl_Products p,tbl_OrderDetail d , tbl_Category c , tbl_Order o \n" +
            "  where p.ProductID = d.ProductID \n" +
            "  and p.CateID = c.CateID \n" +
            "   and o.OrderID = d.OrderID  \n";
           
                if (!string.IsNullOrEmpty(frDate))
                    Query += " And convert(datetime,o.Created,103) BETWEEN convert(datetime,'" + frDate + "',103) ";
                if (!string.IsNullOrEmpty(toDate))
                    Query += " And dateadd(dd,1,convert(datetime,'" + toDate + "',103) "+
                        " )";

                Query += "  group by d.ProductID,p.ProductName,p.NewPrice,c.Title \n";            

            DataTable dtResult = new DataTable();
            dtResult = DB.ViewTableSql(Query);
            return dtResult;
        }

        public string Customers_ProductRender(DataTable dtCustomers)
        {
            string Header = "Customer list";
            
            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divcartholder\" class=\"contactholder\">\n" +
                "	<h1 class=\"title\">" + Header + "</h1>\n" +
                "	<span class=\"legend\">\n" +
                "	</span>\n" +
                "	<div class=\"contactform\">\n" +
                "											\n" +
                "		<table id=\"dtcart\" class=\"carttable\" border>\n" +
                 "			<tr>\n" +
                "				<th class=\"stt\">" + MyResource.Index + "</th>\n" +
                "				<th class=\"stt\">ID</th>\n" +
                "				<th class=\"stt\">Login name</th>\n" +
                "				<th class=\"name\">Full name</th>\n" +
                "				<th class=\"name\">Sex</th>\n" +
                "				<th class=\"price\">Email</th>\n" +
                "				<th class=\"price\">Phone number</th>\n" +
                "				<th class=\"sl\">BirthDay</th>\n" +
                "				<th class=\"sl\">Created</th>\n" +
                "				<th class=\"total\">Address</th>\n" +
                  "				<th class=\"total\">Status</th>\n" +
                "			</tr>\n"
                );            

            for (int i = 0; i < dtCustomers.Rows.Count; i++)
            {                
                Html.Append(

                "			<tr class=\"odd\">\n" +
                "				<td class=\"stt\">" + (i + 1) + "</td>\n" +
                "				<td class=\"stt\">" + dtCustomers.Rows[i]["CustommerID"] + "</td>\n" +
                "				<td class=\"stt\">" + dtCustomers.Rows[i]["LoginName"] + "</td>\n" +
                "				<td class=\"name\">" + dtCustomers.Rows[i]["FullName"] + "</td>\n" +
                "				<td class=\"name\">" + dtCustomers.Rows[i]["_Sex"] + "</td>\n" +
                "				<td class=\"price\">" + dtCustomers.Rows[i]["Email"] + "</td>\n" +
                "				<td class=\"price\">" + dtCustomers.Rows[i]["PhoneNumber"] + "</td>\n" +
                "				<td class=\"sl\">" +  DateTime.Parse(dtCustomers.Rows[i]["Birthday"].ToString()).ToString("dd/MM/yyyy") + "</td>\n" +
                "				<td class=\"sl\">" + DateTime.Parse(dtCustomers.Rows[i]["Created"].ToString()).ToString("dd/MM/yyyy") + "</td>\n" +
                "				<td class=\"total\">" + dtCustomers.Rows[i]["Address"].ToString()+ "</td>\n" +
                 "				<td class=\"total\">" + dtCustomers.Rows[i]["_Active"].ToString() + "</td>\n" +
                "			</tr>\n");
            }
            Html.Append(
                "</table>" +
                "	</div>\n" +
                "</div>\n");
            return Html.ToString();
        }

        public string Reports_OrderRender(DataTable dtOrderStatus)
        {

            string Header = "Order list";

            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div id=\"divcartholder\" class=\"contactholder\">\n" +
                "	<h1 class=\"title\">" + Header + "</h1>\n" +
                "	<span class=\"legend\">\n" +
                "	</span>\n" +
                "	<div class=\"contactform\">\n" +
                "											\n" +
                "		<table id=\"dtcart\" class=\"carttable\" border>\n" +
                 "			<tr>\n" +
                "				<th class=\"stt\">" + MyResource.Index + "</th>\n" +
                "				<th class=\"stt\">ID</th>\n" +
                "				<th class=\"stt\">Customer</th>\n" +
                "				<th class=\"name\">Email</th>\n" +
                "				<th class=\"name\">Phone number</th>\n" +                
                "				<th class=\"sl\">Created</th>\n" +
                "				<th class=\"total\">"+MyResource.Amount+"</th>\n" +
                  "				<th class=\"total\">Status</th>\n" +
                "			</tr>\n"
                );

            for (int i = 0; i < dtOrderStatus.Rows.Count; i++)
            {//("#,###")
                float Total = float.Parse(dtOrderStatus.Rows[i]["Total"].ToString());
                Html.Append(

                "			<tr class=\"odd\">\n" +
                "				<td class=\"stt\">" + (i + 1) + "</td>\n" +
                "				<td class=\"stt\">" + dtOrderStatus.Rows[i]["OrderId"] + "</td>\n" +                
                "				<td class=\"name\">" + dtOrderStatus.Rows[i]["FullName"] + "</td>\n" +
                //"				<td class=\"name\">" + dtOrderStatus.Rows[i]["_Sex"] + "</td>\n" +
                "				<td class=\"price\">" + dtOrderStatus.Rows[i]["Email"] + "</td>\n" +
                "				<td class=\"price\">" + dtOrderStatus.Rows[i]["PhoneNumber"] + "</td>\n" +
                //"				<td class=\"sl\">" + DateTime.Parse(dtOrderStatus.Rows[i]["Birthday"].ToString()).ToString("dd/MM/yyyy") + "</td>\n" +
                "				<td class=\"sl\">" + DateTime.Parse(dtOrderStatus.Rows[i]["Created"].ToString()).ToString("dd/MM/yyyy") + "</td>\n" +
                "				<td class=\"sl\">" + Total.ToString("#,###") + "(vnd) </td>\n" +                
                "				<td class=\"total\">" + dtOrderStatus.Rows[i]["StatusName"].ToString() + "</td>\n" +
                "			</tr>\n");
            }
            Html.Append(
                "</table>" +
                "	</div>\n" +
                "</div>\n");
            return Html.ToString();
        }
    }
}